Browse Source

优化读写逻辑

bugfix
zhuangjiaju 5 years ago
parent
commit
13a7f609eb
  1. 30
      src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java
  2. 2
      src/test/java/com/alibaba/easyexcel/test/temp/Xls03Test.java

30
src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java

@ -111,6 +111,10 @@ public class XlsSaxAnalyser implements HSSFListener, ExcelExecutor {
} catch (IOException e) { } catch (IOException e) {
throw new ExcelAnalysisException(e); throw new ExcelAnalysisException(e);
} }
// Sometimes tables lack the end record of the last column
if (!records.isEmpty()) {
endRow();
}
} }
private void init() { private void init() {
@ -168,19 +172,21 @@ public class XlsSaxAnalyser implements HSSFListener, ExcelExecutor {
private void processLastCellOfRow(Record record) { private void processLastCellOfRow(Record record) {
// Handle end of row // Handle end of row
if (record instanceof LastCellOfRowDummyRecord) { if (record instanceof LastCellOfRowDummyRecord) {
int row = ((LastCellOfRowDummyRecord)record).getRow(); endRow();
if (lastColumnNumber == -1) { }
lastColumnNumber = 0; }
}
if (notAllEmpty) { private void endRow() {
analysisContext.readRowHolder( if (lastColumnNumber == -1) {
new ReadRowHolder(lastRowNumber, analysisContext.readSheetHolder().getGlobalConfiguration())); lastColumnNumber = 0;
analysisContext.readSheetHolder().notifyEndOneRow(new EachRowAnalysisFinishEvent(records), }
analysisContext); if (notAllEmpty) {
} analysisContext.readRowHolder(
records.clear(); new ReadRowHolder(lastRowNumber, analysisContext.readSheetHolder().getGlobalConfiguration()));
lastColumnNumber = -1; analysisContext.readSheetHolder().notifyEndOneRow(new EachRowAnalysisFinishEvent(records), analysisContext);
} }
records.clear();
lastColumnNumber = -1;
} }
private void buildXlsRecordHandlers() { private void buildXlsRecordHandlers() {

2
src/test/java/com/alibaba/easyexcel/test/temp/Xls03Test.java

@ -21,7 +21,7 @@ public class Xls03Test {
@Test @Test
public void test() { public void test() {
List<Object> list = EasyExcelFactory.read("D:\\test\\1.xls").sheet().doReadSync(); List<Object> list = EasyExcelFactory.read("D:\\test\\8.xls").sheet().doReadSync();
for (Object data : list) { for (Object data : list) {
LOGGER.info("返回数据:{}", JSON.toJSONString(data)); LOGGER.info("返回数据:{}", JSON.toJSONString(data));
} }

Loading…
Cancel
Save