Browse Source

修改填充数据空数据的bug #1274

pull/1276/head v2.2.3
Jiaju Zhuang 5 years ago
parent
commit
fba1f72daa
  1. 2
      pom.xml
  2. 11
      src/main/java/com/alibaba/excel/converters/NullableObjectConverter.java
  3. 14
      src/main/java/com/alibaba/excel/write/executor/AbstractExcelWriteExecutor.java
  4. 3
      src/test/java/com/alibaba/easyexcel/test/core/fill/FillDataTest.java
  5. 4
      update.md

2
pom.xml

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId> <artifactId>easyexcel</artifactId>
<version>2.2.2</version> <version>2.2.3</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>easyexcel</name> <name>easyexcel</name>

11
src/main/java/com/alibaba/excel/converters/NullableObjectConverter.java

@ -1,11 +0,0 @@
package com.alibaba.excel.converters;
/**
* When implementing <code>convertToExcelData</code> method, pay attention to the reference <code>value</code> may be
* null
*
* @author JiaJu Zhuang
**/
public interface NullableObjectConverter<T> extends Converter<T> {
}

14
src/main/java/com/alibaba/excel/write/executor/AbstractExcelWriteExecutor.java

@ -10,7 +10,6 @@ import org.apache.poi.ss.usermodel.Sheet;
import com.alibaba.excel.context.WriteContext; import com.alibaba.excel.context.WriteContext;
import com.alibaba.excel.converters.Converter; import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ConverterKeyBuild; import com.alibaba.excel.converters.ConverterKeyBuild;
import com.alibaba.excel.converters.NullableObjectConverter;
import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.exception.ExcelDataConvertException; import com.alibaba.excel.exception.ExcelDataConvertException;
import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.CellData;
@ -33,9 +32,10 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
protected CellData converterAndSet(WriteHolder currentWriteHolder, Class clazz, Cell cell, Object value, protected CellData converterAndSet(WriteHolder currentWriteHolder, Class clazz, Cell cell, Object value,
ExcelContentProperty excelContentProperty, Head head, Integer relativeRowIndex) { ExcelContentProperty excelContentProperty, Head head, Integer relativeRowIndex) {
boolean needTrim = if (value == null) {
value != null && (value instanceof String && currentWriteHolder.globalConfiguration().getAutoTrim()); return new CellData(CellDataTypeEnum.EMPTY);
if (needTrim) { }
if (value instanceof String && currentWriteHolder.globalConfiguration().getAutoTrim()) {
value = ((String)value).trim(); value = ((String)value).trim();
} }
CellData cellData = convert(currentWriteHolder, clazz, cell, value, excelContentProperty); CellData cellData = convert(currentWriteHolder, clazz, cell, value, excelContentProperty);
@ -70,6 +70,9 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
protected CellData convert(WriteHolder currentWriteHolder, Class clazz, Cell cell, Object value, protected CellData convert(WriteHolder currentWriteHolder, Class clazz, Cell cell, Object value,
ExcelContentProperty excelContentProperty) { ExcelContentProperty excelContentProperty) {
if (value == null) {
return new CellData(CellDataTypeEnum.EMPTY);
}
// This means that the user has defined the data. // This means that the user has defined the data.
if (value instanceof CellData) { if (value instanceof CellData) {
CellData cellDataValue = (CellData)value; CellData cellDataValue = (CellData)value;
@ -107,9 +110,6 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
new CellData(CellDataTypeEnum.EMPTY), excelContentProperty, new CellData(CellDataTypeEnum.EMPTY), excelContentProperty,
"Can not find 'Converter' support class " + clazz.getSimpleName() + "."); "Can not find 'Converter' support class " + clazz.getSimpleName() + ".");
} }
if (value == null && !(converter instanceof NullableObjectConverter)) {
return new CellData(CellDataTypeEnum.EMPTY);
}
CellData cellData; CellData cellData;
try { try {
cellData = cellData =

3
src/test/java/com/alibaba/easyexcel/test/core/fill/FillDataTest.java

@ -203,6 +203,9 @@ public class FillDataTest {
list.add(fillData); list.add(fillData);
fillData.setName("张三"); fillData.setName("张三");
fillData.setNumber(5.2); fillData.setNumber(5.2);
if (i == 5) {
fillData.setName(null);
}
} }
return list; return list;
} }

4
update.md

@ -1,3 +1,7 @@
# 2.2.3
* 修改填充数据空数据的bug [Issue #1274](https://github.com/alibaba/easyexcel/issues/1274)
* 回退自定义转换器入参为空
# 2.2.2 # 2.2.2
* 修改`sheet`事件未调用的bug * 修改`sheet`事件未调用的bug

Loading…
Cancel
Save