Browse Source

* 支持停止单个`sheet`以后继续读取其他`sheet`,使用`ExcelAnalysisStopSheetException`

pull/3720/head
是仪 9 months ago
parent
commit
abcd4f77f2
  1. 8
      easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java

8
easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java

@ -16,6 +16,8 @@ import com.alibaba.excel.enums.ByteOrderMarkEnum;
import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.enums.RowTypeEnum; import com.alibaba.excel.enums.RowTypeEnum;
import com.alibaba.excel.exception.ExcelAnalysisException; import com.alibaba.excel.exception.ExcelAnalysisException;
import com.alibaba.excel.exception.ExcelAnalysisStopException;
import com.alibaba.excel.exception.ExcelAnalysisStopSheetException;
import com.alibaba.excel.metadata.Cell; import com.alibaba.excel.metadata.Cell;
import com.alibaba.excel.metadata.data.ReadCellData; import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.metadata.ReadSheet; import com.alibaba.excel.read.metadata.ReadSheet;
@ -69,6 +71,7 @@ public class CsvExcelReadExecutor implements ExcelReadExecutor {
if (readSheet == null) { if (readSheet == null) {
continue; continue;
} }
try {
csvReadContext.currentSheet(readSheet); csvReadContext.currentSheet(readSheet);
int rowIndex = 0; int rowIndex = 0;
@ -76,6 +79,11 @@ public class CsvExcelReadExecutor implements ExcelReadExecutor {
for (CSVRecord record : csvParser) { for (CSVRecord record : csvParser) {
dealRecord(record, rowIndex++); dealRecord(record, rowIndex++);
} }
} catch (ExcelAnalysisStopSheetException e) {
if (log.isDebugEnabled()) {
log.debug("Custom stop!", e);
}
}
// The last sheet is read // The last sheet is read
csvReadContext.analysisEventProcessor().endSheet(csvReadContext); csvReadContext.analysisEventProcessor().endSheet(csvReadContext);

Loading…
Cancel
Save