Search in sources :

Example 11 with ExcelAnalysisException

use of com.alibaba.excel.exception.ExcelAnalysisException in project easyexcel by alibaba.

the class CsvExcelReadExecutor method execute.

@Override
public void execute() {
    CSVParser csvParser;
    try {
        csvParser = csvParser();
        csvReadContext.csvReadWorkbookHolder().setCsvParser(csvParser);
    } catch (IOException e) {
        throw new ExcelAnalysisException(e);
    }
    for (ReadSheet readSheet : sheetList) {
        readSheet = SheetUtils.match(readSheet, csvReadContext);
        if (readSheet == null) {
            continue;
        }
        csvReadContext.currentSheet(readSheet);
        int rowIndex = 0;
        for (CSVRecord record : csvParser) {
            dealRecord(record, rowIndex++);
        }
        // The last sheet is read
        csvReadContext.analysisEventProcessor().endSheet(csvReadContext);
    }
}
Also used : CSVParser(org.apache.commons.csv.CSVParser) CSVRecord(org.apache.commons.csv.CSVRecord) IOException(java.io.IOException) ReadSheet(com.alibaba.excel.read.metadata.ReadSheet) ExcelAnalysisException(com.alibaba.excel.exception.ExcelAnalysisException)

Example 12 with ExcelAnalysisException

use of com.alibaba.excel.exception.ExcelAnalysisException in project easyexcel by alibaba.

the class AnalysisContextImpl method currentSheet.

@Override
public void currentSheet(ReadSheet readSheet) {
    switch(readWorkbookHolder.getExcelType()) {
        case XLS:
            readSheetHolder = new XlsReadSheetHolder(readSheet, readWorkbookHolder);
            break;
        case XLSX:
            readSheetHolder = new XlsxReadSheetHolder(readSheet, readWorkbookHolder);
            break;
        case CSV:
            readSheetHolder = new CsvReadSheetHolder(readSheet, readWorkbookHolder);
            break;
        default:
            break;
    }
    currentReadHolder = readSheetHolder;
    if (readWorkbookHolder.getHasReadSheet().contains(readSheetHolder.getSheetNo())) {
        throw new ExcelAnalysisException("Cannot read sheet repeatedly.");
    }
    readWorkbookHolder.getHasReadSheet().add(readSheetHolder.getSheetNo());
    if (log.isDebugEnabled()) {
        log.debug("Began to read:{}", readSheetHolder);
    }
}
Also used : XlsxReadSheetHolder(com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder) CsvReadSheetHolder(com.alibaba.excel.read.metadata.holder.csv.CsvReadSheetHolder) XlsReadSheetHolder(com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder) ExcelAnalysisException(com.alibaba.excel.exception.ExcelAnalysisException)

Aggregations

ExcelAnalysisException (com.alibaba.excel.exception.ExcelAnalysisException)12 IOException (java.io.IOException)5 ExcelDataConvertException (com.alibaba.excel.exception.ExcelDataConvertException)3 ConstraintViolation (javax.validation.ConstraintViolation)3 ConstraintViolationException (javax.validation.ConstraintViolationException)3 XlsReadWorkbookHolder (com.alibaba.excel.read.metadata.holder.xls.XlsReadWorkbookHolder)2 EventWorkbookBuilder (org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder)2 FormatTrackingHSSFListener (org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener)2 HSSFEventFactory (org.apache.poi.hssf.eventusermodel.HSSFEventFactory)2 HSSFRequest (org.apache.poi.hssf.eventusermodel.HSSFRequest)2 MissingRecordAwareHSSFListener (org.apache.poi.hssf.eventusermodel.MissingRecordAwareHSSFListener)2 SyncReadListener (com.alibaba.excel.event.SyncReadListener)1 ExcelAnalysisStopException (com.alibaba.excel.exception.ExcelAnalysisStopException)1 ExcelCommonException (com.alibaba.excel.exception.ExcelCommonException)1 ReadSheet (com.alibaba.excel.read.metadata.ReadSheet)1 ReadWorkbookHolder (com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder)1 CsvReadSheetHolder (com.alibaba.excel.read.metadata.holder.csv.CsvReadSheetHolder)1 CsvReadWorkbookHolder (com.alibaba.excel.read.metadata.holder.csv.CsvReadWorkbookHolder)1 XlsReadSheetHolder (com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder)1 XlsxReadSheetHolder (com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder)1