Search in sources :

Example 1 with ExcelAnalysisStopException

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);
    }
}
Also used : ExcelAnalysisStopException(com.alibaba.excel.exception.ExcelAnalysisStopException) ExcelAnalysisException(com.alibaba.excel.exception.ExcelAnalysisException)

Example 2 with ExcelAnalysisStopException

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.");
    }
}
Also used : ArrayList(java.util.ArrayList) ExcelAnalysisStopException(com.alibaba.excel.exception.ExcelAnalysisStopException) ReadSheet(com.alibaba.excel.read.metadata.ReadSheet) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord)

Example 3 with ExcelAnalysisStopException

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();
        }
    }
}
Also used : ReadCellData(com.alibaba.excel.metadata.data.ReadCellData) ReadRowHolder(com.alibaba.excel.read.metadata.holder.ReadRowHolder) ExcelAnalysisStopException(com.alibaba.excel.exception.ExcelAnalysisStopException) HashMap(java.util.HashMap) Map(java.util.Map) ReadListener(com.alibaba.excel.read.listener.ReadListener) ExcelAnalysisStopException(com.alibaba.excel.exception.ExcelAnalysisStopException) ExcelAnalysisException(com.alibaba.excel.exception.ExcelAnalysisException)

Aggregations

ExcelAnalysisStopException (com.alibaba.excel.exception.ExcelAnalysisStopException)3 ExcelAnalysisException (com.alibaba.excel.exception.ExcelAnalysisException)2 ReadCellData (com.alibaba.excel.metadata.data.ReadCellData)1 ReadListener (com.alibaba.excel.read.listener.ReadListener)1 ReadSheet (com.alibaba.excel.read.metadata.ReadSheet)1 ReadRowHolder (com.alibaba.excel.read.metadata.holder.ReadRowHolder)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BoundSheetRecord (org.apache.poi.hssf.record.BoundSheetRecord)1