use of com.alibaba.excel.exception.ExcelAnalysisStopException in project easyexcel by alibaba.
the class ExcelAnalyserImpl method analysis.
@Override
public void analysis(List<ReadSheet> readSheetList, Boolean readAll) {
try {
if (!readAll && CollectionUtils.isEmpty(readSheetList)) {
throw new IllegalArgumentException("Specify at least one read sheet.");
}
analysisContext.readWorkbookHolder().setParameterSheetDataList(readSheetList);
analysisContext.readWorkbookHolder().setReadAll(readAll);
try {
excelReadExecutor.execute();
} catch (ExcelAnalysisStopException e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Custom stop!");
}
}
} catch (RuntimeException e) {
finish();
throw e;
} catch (Throwable e) {
finish();
throw new ExcelAnalysisException(e);
}
}
use of com.alibaba.excel.exception.ExcelAnalysisStopException in project easyexcel by alibaba.
the class BofRecordHandler method initReadSheetDataList.
private void initReadSheetDataList(XlsReadWorkbookHolder xlsReadWorkbookHolder) {
if (xlsReadWorkbookHolder.getActualSheetDataList() != null) {
return;
}
BoundSheetRecord[] boundSheetRecords = BoundSheetRecord.orderByBofPosition(xlsReadWorkbookHolder.getBoundSheetRecordList());
List<ReadSheet> readSheetDataList = new ArrayList<ReadSheet>();
for (int i = 0; i < boundSheetRecords.length; i++) {
BoundSheetRecord boundSheetRecord = boundSheetRecords[i];
ReadSheet readSheet = new ReadSheet(i, boundSheetRecord.getSheetname());
readSheetDataList.add(readSheet);
}
xlsReadWorkbookHolder.setActualSheetDataList(readSheetDataList);
// Just need to get the list of sheets
if (!xlsReadWorkbookHolder.getNeedReadSheet()) {
throw new ExcelAnalysisStopException("Just need to get the list of sheets.");
}
}
use of com.alibaba.excel.exception.ExcelAnalysisStopException in project easyexcel by alibaba.
the class DefaultAnalysisEventProcessor method dealData.
private void dealData(AnalysisContext analysisContext) {
ReadRowHolder readRowHolder = analysisContext.readRowHolder();
Map<Integer, ReadCellData<?>> cellDataMap = (Map) readRowHolder.getCellMap();
readRowHolder.setCurrentRowAnalysisResult(cellDataMap);
int rowIndex = readRowHolder.getRowIndex();
int currentHeadRowNumber = analysisContext.readSheetHolder().getHeadRowNumber();
boolean isData = rowIndex >= currentHeadRowNumber;
// Last head column
if (!isData && currentHeadRowNumber == rowIndex + 1) {
buildHead(analysisContext, cellDataMap);
}
// Now is data
for (ReadListener readListener : analysisContext.currentReadHolder().readListenerList()) {
try {
if (isData) {
readListener.invoke(readRowHolder.getCurrentRowAnalysisResult(), analysisContext);
} else {
readListener.invokeHead(cellDataMap, analysisContext);
}
} catch (Exception e) {
onException(analysisContext, e);
break;
}
if (!readListener.hasNext(analysisContext)) {
throw new ExcelAnalysisStopException();
}
}
}
Aggregations