Browse Source

修复xls直接读取第2页 `NPE` 的bug #1280

pull/1391/head
Jiaju Zhuang 5 years ago
parent
commit
927f6b410f
  1. 9
      src/main/java/com/alibaba/excel/analysis/v03/handlers/BofRecordHandler.java
  2. 4
      src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java
  3. 1
      update.md

9
src/main/java/com/alibaba/excel/analysis/v03/handlers/BofRecordHandler.java

@ -22,7 +22,7 @@ public class BofRecordHandler extends AbstractXlsRecordHandler {
@Override @Override
public void processRecord(XlsReadContext xlsReadContext, Record record) { public void processRecord(XlsReadContext xlsReadContext, Record record) {
BOFRecord br = (BOFRecord)record; BOFRecord br = (BOFRecord) record;
XlsReadWorkbookHolder xlsReadWorkbookHolder = xlsReadContext.xlsReadWorkbookHolder(); XlsReadWorkbookHolder xlsReadWorkbookHolder = xlsReadContext.xlsReadWorkbookHolder();
if (br.getType() == BOFRecord.TYPE_WORKBOOK) { if (br.getType() == BOFRecord.TYPE_WORKBOOK) {
xlsReadWorkbookHolder.setReadSheetIndex(null); xlsReadWorkbookHolder.setReadSheetIndex(null);
@ -38,14 +38,15 @@ public class BofRecordHandler extends AbstractXlsRecordHandler {
readSheetIndex = 0; readSheetIndex = 0;
xlsReadWorkbookHolder.setReadSheetIndex(readSheetIndex); xlsReadWorkbookHolder.setReadSheetIndex(readSheetIndex);
} }
ReadSheet readSheet = xlsReadWorkbookHolder.getActualSheetDataList().get(readSheetIndex); ReadSheet actualReadSheet = xlsReadWorkbookHolder.getActualSheetDataList().get(readSheetIndex);
assert readSheet != null : "Can't find the sheet."; assert actualReadSheet != null : "Can't find the sheet.";
// Copy the parameter to the current sheet // Copy the parameter to the current sheet
readSheet = SheetUtils.match(readSheet, xlsReadContext); ReadSheet readSheet = SheetUtils.match(actualReadSheet, xlsReadContext);
if (readSheet != null) { if (readSheet != null) {
xlsReadContext.currentSheet(readSheet); xlsReadContext.currentSheet(readSheet);
xlsReadContext.xlsReadSheetHolder().setIgnoreRecord(Boolean.FALSE); xlsReadContext.xlsReadSheetHolder().setIgnoreRecord(Boolean.FALSE);
} else { } else {
xlsReadContext.currentSheet(actualReadSheet);
xlsReadContext.xlsReadSheetHolder().setIgnoreRecord(Boolean.TRUE); xlsReadContext.xlsReadSheetHolder().setIgnoreRecord(Boolean.TRUE);
} }
// Go read the next one // Go read the next one

4
src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java

@ -32,9 +32,9 @@ public class Lock2Test {
@Test @Test
public void test() throws Exception { public void test() throws Exception {
File file = TestFileUtil.readUserHomeFile("test/test4.xlsx"); File file = TestFileUtil.readUserHomeFile("test/test6.xls");
List<Object> list = EasyExcel.read(file).sheet().headRowNumber(0).doReadSync(); List<Object> list = EasyExcel.read(file).sheet(1).headRowNumber(0).doReadSync();
LOGGER.info("数据:{}", list.size()); LOGGER.info("数据:{}", list.size());
for (Object data : list) { for (Object data : list) {
LOGGER.info("返回数据:{}", JSON.toJSONString(data)); LOGGER.info("返回数据:{}", JSON.toJSONString(data));

1
update.md

@ -6,6 +6,7 @@
* 修复多个`sheet`不按照顺序写入 会乱序的bug [Issue #1332](https://github.com/alibaba/easyexcel/issues/1332) * 修复多个`sheet`不按照顺序写入 会乱序的bug [Issue #1332](https://github.com/alibaba/easyexcel/issues/1332)
* 修改head是List时,内容单元格的样式不生效 [Issue #1339](https://github.com/alibaba/easyexcel/issues/1339) * 修改head是List时,内容单元格的样式不生效 [Issue #1339](https://github.com/alibaba/easyexcel/issues/1339)
* 修复xls仅公式行 不读取的bug [Issue #1324](https://github.com/alibaba/easyexcel/issues/1324) * 修复xls仅公式行 不读取的bug [Issue #1324](https://github.com/alibaba/easyexcel/issues/1324)
* 修复xls直接读取第2页 `NPE` 的bug [Issue #1280](https://github.com/alibaba/easyexcel/issues/1280)
# 2.2.3 # 2.2.3

Loading…
Cancel
Save