Browse Source

Merge branch 'master' into 2.0.1

# Conflicts:
#	src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java
#	src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java
#	src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java
#	src/test/java/com/alibaba/easyexcel/test/temp/simple/HgTest.java
bugfix
Jiaju Zhuang 5 years ago
parent
commit
fd860956d9
  1. 6
      pom.xml
  2. 2
      quickstart.md
  3. 4
      src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
  4. 12
      src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java
  5. 2
      src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java
  6. 1
      src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java
  7. 9
      src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java
  8. 6
      src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java
  9. 3
      src/test/java/com/alibaba/easyexcel/test/core/converter/ReadAllConverterDataListener.java
  10. 2
      src/test/java/com/alibaba/easyexcel/test/temp/simple/HgTest.java
  11. 5
      update.md

6
pom.xml

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.0.0-beta6</version>
<version>2.0.0</version>
<packaging>jar</packaging>
<name>easyexcel</name>
@ -59,12 +59,12 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.1</version>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.1</version>
<version>3.17</version>
</dependency>
<dependency>
<groupId>cglib</groupId>

2
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。

4
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 {

12
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<String> currentTagDeque = new LinkedList<String>();
private int curCol;
private Map<Integer, CellData> curRowContent = new TreeMap<Integer, CellData>();
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;
}

2
src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java

@ -27,7 +27,7 @@ public class BooleanNumberConverter implements Converter<Boolean> {
@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;

1
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;

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

6
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<Integer, Map<Integer, Integer>> cache = new HashMap<Integer, Map<Integer, Integer>>(8);
private static final Map<Integer, Map<Integer, Integer>> CACHE = new HashMap<Integer, Map<Integer, Integer>>(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<Integer, Integer> maxColumnWidthMap = cache.get(writeSheetHolder.getSheetNo());
Map<Integer, Integer> maxColumnWidthMap = CACHE.get(writeSheetHolder.getSheetNo());
if (maxColumnWidthMap == null) {
maxColumnWidthMap = new HashMap<Integer, Integer>(16);
cache.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap);
CACHE.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap);
}
Integer columnWidth = dataLength(cellData, cell, isHead);
if (columnWidth < 0) {

3
src/test/java/com/alibaba/easyexcel/test/core/converter/ReadAllConverterDataListener.java

@ -65,7 +65,8 @@ public class ReadAllConverterDataListener extends AnalysisEventListener<ReadAllC
Assert.assertEquals(data.getStringString(), "测试");
Assert.assertEquals(data.getStringError(), "#VALUE!");
Assert.assertEquals(data.getStringNumberDate(), "2020-01-01 01:01:01");
Assert.assertEquals(data.getStringFormulaNumber(), "2.0");
double doubleStringFormulaNumber = new BigDecimal(data.getStringFormulaNumber()).doubleValue();
Assert.assertEquals(doubleStringFormulaNumber, 2.0, 0.0);
Assert.assertEquals(data.getStringFormulaString(), "1测试");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
}

2
src/test/java/com/alibaba/easyexcel/test/temp/simple/HgTest.java

@ -24,7 +24,7 @@ public class HgTest {
@Test
public void hh() throws IOException {
List<Object> 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));
}

5
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<String>>,但是数据用List<Class>导致的空指针

Loading…
Cancel
Save