提交 927f6b41 编写于 作者: 庄家钜's avatar 庄家钜

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

上级 58fdceb2
...@@ -22,7 +22,7 @@ public class BofRecordHandler extends AbstractXlsRecordHandler { ...@@ -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 { ...@@ -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
......
...@@ -32,9 +32,9 @@ public class Lock2Test { ...@@ -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));
......
...@@ -6,6 +6,7 @@ ...@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册