diff --git a/pom.xml b/pom.xml
index 0a629230..754c945e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
com.alibaba
easyexcel
- 2.0.0-beta6
+ 2.0.0
jar
easyexcel
@@ -59,12 +59,12 @@
org.apache.poi
poi
- 4.0.1
+ 3.17
org.apache.poi
poi-ooxml
- 4.0.1
+ 3.17
cglib
diff --git a/quickstart.md b/quickstart.md
index fccc2a84..2b6323f9 100644
--- a/quickstart.md
+++ b/quickstart.md
@@ -8,7 +8,7 @@
* 读取图片
* 宏
#### 关于版本兼容
-目前poi用的 4.0.1 建议检查是否该版本。如果出现找不到class之类的,八成就是这个原因。
+目前poi用的 4.0.1 建议检查是否该版本。如果看到`NoClassDefFoundError`或者`ClassNotFoundException`,请查看poi相关版本是否都为4.0.1。
#### 详细参数介绍
有些参数不知道怎么用,或者有些功能不知道用什么参数,参照:[详细参数介绍](/docs/API.md)
#### 开源项目不容易,如果觉得本项目对您的工作还是有帮助的话,请在右上角帮忙点个★Star。
diff --git a/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java b/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
index 5adc237e..dcae5f1b 100644
--- a/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
+++ b/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
@@ -15,7 +15,6 @@ import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.context.AnalysisContextImpl;
import com.alibaba.excel.exception.ExcelAnalysisException;
import com.alibaba.excel.exception.ExcelAnalysisStopException;
-import com.alibaba.excel.exception.ExcelGenerateException;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.read.metadata.ReadWorkbook;
import com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder;
@@ -64,7 +63,8 @@ public class ExcelAnalyserImpl implements ExcelAnalyser {
if (poifsFileSystem.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) {
InputStream decryptedStream = null;
try {
- decryptedStream = DocumentFactoryHelper.getDecryptedStream(poifsFileSystem.getRoot(), null);
+ decryptedStream =
+ DocumentFactoryHelper.getDecryptedStream(poifsFileSystem.getRoot().getFileSystem(), null);
excelExecutor = new XlsxSaxAnalyser(analysisContext, decryptedStream);
return;
} finally {
diff --git a/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java
index 5a52c996..c0ad7064 100644
--- a/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java
+++ b/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java
@@ -8,6 +8,8 @@ import static com.alibaba.excel.constant.ExcelXmlConstants.CELL_VALUE_TAG;
import static com.alibaba.excel.constant.ExcelXmlConstants.CELL_VALUE_TYPE_TAG;
import java.math.BigDecimal;
+import java.util.Deque;
+import java.util.LinkedList;
import java.util.Map;
import java.util.TreeMap;
@@ -34,8 +36,7 @@ import com.alibaba.excel.util.StringUtils;
*/
public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder {
private final AnalysisContext analysisContext;
- private String currentTag;
- private String currentCellIndex;
+ private Deque currentTagDeque = new LinkedList();
private int curCol;
private Map curRowContent = new TreeMap();
private CellData currentCellData;
@@ -62,11 +63,10 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder
@Override
public void startHandle(String name, Attributes attributes) {
- currentTag = name;
+ currentTagDeque.push(name);
// start a cell
if (CELL_TAG.equals(name)) {
- currentCellIndex = attributes.getValue(ExcelXmlConstants.POSITION);
- curCol = PositionUtils.getCol(currentCellIndex);
+ curCol = PositionUtils.getCol(attributes.getValue(ExcelXmlConstants.POSITION));
// t="s" ,it's means String
// t="str" ,it's means String,but does not need to be read in the 'sharedStrings.xml'
@@ -101,6 +101,7 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder
@Override
public void endHandle(String name) {
+ currentTagDeque.pop();
if (CELL_VALUE_TAG.equals(name)) {
// Have to go "sharedStrings.xml" and get it
if (currentCellData.getType() == CellDataTypeEnum.STRING) {
@@ -134,6 +135,7 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder
if (StringUtils.isEmpty(currentCellValue)) {
return;
}
+ String currentTag = currentTagDeque.peek();
if (currentTag == null) {
return;
}
diff --git a/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java b/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java
index 06ac0c73..a0042eaa 100644
--- a/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java
+++ b/src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java
@@ -27,7 +27,7 @@ public class BooleanNumberConverter implements Converter {
@Override
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
- if (BigDecimal.ONE.equals(cellData.getNumberValue())) {
+ if (BigDecimal.ONE.compareTo(cellData.getNumberValue()) == 0) {
return Boolean.TRUE;
}
return Boolean.FALSE;
diff --git a/src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java b/src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java
index 89cbe1d2..f536a088 100644
--- a/src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java
+++ b/src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java
@@ -2,7 +2,6 @@ package com.alibaba.excel.converters.string;
import java.math.BigDecimal;
-import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.DateUtil;
import com.alibaba.excel.converters.Converter;
diff --git a/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java b/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java
index a267e1de..2f02327c 100644
--- a/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java
+++ b/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java
@@ -1,6 +1,8 @@
package com.alibaba.excel.support;
+import java.io.BufferedInputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -31,7 +33,12 @@ public enum ExcelTypeEnum {
try {
FileMagic fileMagic;
if (file != null) {
- fileMagic = FileMagic.valueOf(file);
+ BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
+ try {
+ fileMagic = FileMagic.valueOf(bufferedInputStream);
+ } finally {
+ bufferedInputStream.close();
+ }
if (!FileMagic.OLE2.equals(fileMagic) && !FileMagic.OOXML.equals(fileMagic)) {
String fileName = file.getName();
if (fileName.endsWith(XLSX.getValue())) {
diff --git a/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java b/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java
index 320573bd..fb807f39 100644
--- a/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java
+++ b/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java
@@ -21,7 +21,7 @@ public class LongestMatchColumnWidthStyleStrategy extends AbstractColumnWidthSty
private static final int MAX_COLUMN_WIDTH = 256;
- Map> cache = new HashMap>(8);
+ private static final Map> CACHE = new HashMap>(8);
@Override
protected void setColumnWidth(WriteSheetHolder writeSheetHolder, CellData cellData, Cell cell, Head head,
@@ -29,10 +29,10 @@ public class LongestMatchColumnWidthStyleStrategy extends AbstractColumnWidthSty
if (!isHead && cellData == null) {
return;
}
- Map maxColumnWidthMap = cache.get(writeSheetHolder.getSheetNo());
+ Map maxColumnWidthMap = CACHE.get(writeSheetHolder.getSheetNo());
if (maxColumnWidthMap == null) {
maxColumnWidthMap = new HashMap(16);
- cache.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap);
+ CACHE.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap);
}
Integer columnWidth = dataLength(cellData, cell, isHead);
if (columnWidth < 0) {
diff --git a/src/test/java/com/alibaba/easyexcel/test/core/converter/ReadAllConverterDataListener.java b/src/test/java/com/alibaba/easyexcel/test/core/converter/ReadAllConverterDataListener.java
index f4f0a1e7..c8b5d8bf 100644
--- a/src/test/java/com/alibaba/easyexcel/test/core/converter/ReadAllConverterDataListener.java
+++ b/src/test/java/com/alibaba/easyexcel/test/core/converter/ReadAllConverterDataListener.java
@@ -65,7 +65,8 @@ public class ReadAllConverterDataListener extends AnalysisEventListener list =
- EasyExcel.read(new FileInputStream("D:\\test\\test.xlsx")).headRowNumber(0).sheet().doReadSync();
+ EasyExcel.read(new FileInputStream("D:\\test\\折扣2007.xls")).headRowNumber(0).sheet().doReadSync();
for (Object data : list) {
LOGGER.info("返回数据:{}", JSON.toJSONString(data));
}
diff --git a/update.md b/update.md
index 60dd1edf..0efb5ef5 100644
--- a/update.md
+++ b/update.md
@@ -1,3 +1,8 @@
+# 2.0.0
+* 修复当cell为空可能会抛出空指针的bug
+* 修复电话等长数字可能出现科学计数法的问题 [Issue #583](https://github.com/alibaba/easyexcel/issues/583)
+* 升级为正式版
+
# 2.0.0-beta6
* 修复空行读取空指针异常
* 修复写入指定头为List>,但是数据用List导致的空指针