From 13a7f609eb7b8ca1b5ad2260c35873d48a9dff60 Mon Sep 17 00:00:00 2001 From: zhuangjiaju Date: Thu, 8 Aug 2019 14:06:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=BB=E5=86=99=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excel/analysis/v03/XlsSaxAnalyser.java | 30 +++++++++++-------- .../easyexcel/test/temp/Xls03Test.java | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) 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 340260c..9275436 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 4d87851..044a806 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)); }