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) {
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() {

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

@ -21,7 +21,7 @@ public class Xls03Test {
@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) {
LOGGER.info("返回数据:{}", JSON.toJSONString(data));
}

Loading…
Cancel
Save