Skip to content

Commit

Permalink
* 支持停止单个sheet以后继续读取其他sheet,使用ExcelAnalysisStopSheetException
Browse files Browse the repository at this point in the history
  • Loading branch information
是仪 committed Mar 11, 2024
1 parent 4cd56ad commit abcd4f7
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.enums.RowTypeEnum;
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.data.ReadCellData;
import com.alibaba.excel.read.metadata.ReadSheet;
Expand Down Expand Up @@ -69,12 +71,18 @@ public void execute() {
if (readSheet == null) {
continue;
}
csvReadContext.currentSheet(readSheet);

int rowIndex = 0;

for (CSVRecord record : csvParser) {
dealRecord(record, rowIndex++);
try {
csvReadContext.currentSheet(readSheet);

int rowIndex = 0;

for (CSVRecord record : csvParser) {
dealRecord(record, rowIndex++);
}
} catch (ExcelAnalysisStopSheetException e) {
if (log.isDebugEnabled()) {
log.debug("Custom stop!", e);
}
}

// The last sheet is read
Expand Down

0 comments on commit abcd4f7

Please sign in to comment.