Browse Source

修复在空字符串的时候 格式转换异常 #520

pull/523/head
Jiaju Zhuang 5 years ago
parent
commit
71a341c05b
  1. 3
      src/main/java/com/alibaba/excel/metadata/CellData.java
  2. 13
      src/test/java/com/alibaba/easyexcel/test/temp/simple/HgTest.java
  3. 1
      update.md

3
src/main/java/com/alibaba/excel/metadata/CellData.java

@ -1,6 +1,7 @@
package com.alibaba.excel.metadata;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.util.StringUtils;
/**
* Excel internal cell data
@ -175,7 +176,7 @@ public class CellData {
switch (type) {
case STRING:
case ERROR:
if (stringValue == null) {
if (StringUtils.isEmpty(stringValue)) {
type = CellDataTypeEnum.EMPTY;
}
return;

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

@ -1,23 +1,14 @@
package com.alibaba.easyexcel.test.temp.simple;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.easyexcel.test.temp.poi.PoiTest;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
@ -32,8 +23,8 @@ public class HgTest {
@Test
public void hh() throws IOException {
List<Object> list =
EasyExcel.read(new FileInputStream("D:\\test\\hg2.xlsx")).sheet().headRowNumber(0).doReadSync();
List<Object> list = EasyExcel.read(new FileInputStream("D:\\test\\hg2.xlsx")).autoTrim(Boolean.FALSE).sheet()
.headRowNumber(0).doReadSync();
for (Object data : list) {
LOGGER.info("返回数据:{}", JSON.toJSONString(data));
}

1
update.md

@ -2,6 +2,7 @@
* 加速gc回收 [Issue #511](https://github.com/alibaba/easyexcel/issues/511)
* 修改空字符串读取可能读取上个字段的数据的bug
* 修改换行数据无法读取的bug
* 修复在空字符串的时候 格式转换异常 [Issue #520](https://github.com/alibaba/easyexcel/issues/520)
# 2.0.0-beta1
* 优化读写逻辑

Loading…
Cancel
Save