Skip to content

Commit

Permalink
修复没有样式的情况下空指针异常 #1738
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuangjiaju committed Apr 9, 2021
1 parent 6316eda commit 961be2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.alibaba.excel.analysis.v07.handlers;

import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.xml.sax.Attributes;

import com.alibaba.excel.constant.BuiltinFormats;
import com.alibaba.excel.constant.ExcelXmlConstants;
import com.alibaba.excel.context.xlsx.XlsxReadContext;
Expand All @@ -12,6 +9,10 @@
import com.alibaba.excel.util.PositionUtils;
import com.alibaba.excel.util.StringUtils;

import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.xml.sax.Attributes;

/**
* Cell Handler
*
Expand Down Expand Up @@ -46,8 +47,11 @@ public void startElement(XlsxReadContext xlsxReadContext, String name, Attribute
} else {
dateFormatIndexInteger = Integer.parseInt(dateFormatIndex);
}
XSSFCellStyle xssfCellStyle =
xlsxReadContext.xlsxReadWorkbookHolder().getStylesTable().getStyleAt(dateFormatIndexInteger);
StylesTable stylesTable = xlsxReadContext.xlsxReadWorkbookHolder().getStylesTable();
if (stylesTable == null) {
return;
}
XSSFCellStyle xssfCellStyle = stylesTable.getStyleAt(dateFormatIndexInteger);
int dataFormat = xssfCellStyle.getDataFormat();
xlsxReadSheetHolder.getTempCellData().setDataFormat(dataFormat);
xlsxReadSheetHolder.getTempCellData().setDataFormatString(BuiltinFormats.getBuiltinFormat(dataFormat,
Expand Down
2 changes: 2 additions & 0 deletions update.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* 优化读取性能
* 修复部分情况下不抛出异常
* 07版在导出的时候会导出 行数 [Issue #1282](https://github.com/alibaba/easyexcel/issues/1282)
* 修复没有样式的情况下空指针异常 [Issue #1738](https://github.com/alibaba/easyexcel/issues/1738)


# 2.2.8
* 兼容07在特殊的excel的情况下,读取数据异常
Expand Down

0 comments on commit 961be2d

Please sign in to comment.