diff --git a/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java b/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java index 340260c8..92754360 100644 --- a/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java +++ b/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java @@ -111,6 +111,10 @@ public class XlsSaxAnalyser implements HSSFListener, ExcelExecutor { } catch (IOException e) { throw new ExcelAnalysisException(e); } + // Sometimes tables lack the end record of the last column + if (!records.isEmpty()) { + endRow(); + } } private void init() { @@ -168,19 +172,21 @@ public class XlsSaxAnalyser implements HSSFListener, ExcelExecutor { private void processLastCellOfRow(Record record) { // Handle end of row if (record instanceof LastCellOfRowDummyRecord) { - int row = ((LastCellOfRowDummyRecord)record).getRow(); - if (lastColumnNumber == -1) { - lastColumnNumber = 0; - } - if (notAllEmpty) { - analysisContext.readRowHolder( - new ReadRowHolder(lastRowNumber, analysisContext.readSheetHolder().getGlobalConfiguration())); - analysisContext.readSheetHolder().notifyEndOneRow(new EachRowAnalysisFinishEvent(records), - analysisContext); - } - records.clear(); - lastColumnNumber = -1; + endRow(); + } + } + + private void endRow() { + if (lastColumnNumber == -1) { + lastColumnNumber = 0; + } + if (notAllEmpty) { + analysisContext.readRowHolder( + new ReadRowHolder(lastRowNumber, analysisContext.readSheetHolder().getGlobalConfiguration())); + analysisContext.readSheetHolder().notifyEndOneRow(new EachRowAnalysisFinishEvent(records), analysisContext); } + records.clear(); + lastColumnNumber = -1; } private void buildXlsRecordHandlers() { diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/Xls03Test.java b/src/test/java/com/alibaba/easyexcel/test/temp/Xls03Test.java index 4d87851f..044a8063 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/Xls03Test.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/Xls03Test.java @@ -21,7 +21,7 @@ public class Xls03Test { @Test public void test() { - List list = EasyExcelFactory.read("D:\\test\\1.xls").sheet().doReadSync(); + List list = EasyExcelFactory.read("D:\\test\\8.xls").sheet().doReadSync(); for (Object data : list) { LOGGER.info("返回数据:{}", JSON.toJSONString(data)); }