Browse Source

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

developing 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>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.2</version>
<version>2.2.3</version>
<packaging>jar</packaging>
<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.converters.Converter;
import com.alibaba.excel.converters.ConverterKeyBuild;
import com.alibaba.excel.converters.NullableObjectConverter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.exception.ExcelDataConvertException;
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,
ExcelContentProperty excelContentProperty, Head head, Integer relativeRowIndex) {
boolean needTrim =
value != null && (value instanceof String && currentWriteHolder.globalConfiguration().getAutoTrim());
if (needTrim) {
if (value == null) {
return new CellData(CellDataTypeEnum.EMPTY);
}
if (value instanceof String && currentWriteHolder.globalConfiguration().getAutoTrim()) {
value = ((String)value).trim();
}
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,
ExcelContentProperty excelContentProperty) {
if (value == null) {
return new CellData(CellDataTypeEnum.EMPTY);
}
// This means that the user has defined the data.
if (value instanceof CellData) {
CellData cellDataValue = (CellData)value;
@ -107,9 +110,6 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
new CellData(CellDataTypeEnum.EMPTY), excelContentProperty,
"Can not find 'Converter' support class " + clazz.getSimpleName() + ".");
}
if (value == null && !(converter instanceof NullableObjectConverter)) {
return new CellData(CellDataTypeEnum.EMPTY);
}
CellData cellData;
try {
cellData =

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

@ -203,6 +203,9 @@ public class FillDataTest {
list.add(fillData);
fillData.setName("张三");
fillData.setNumber(5.2);
if (i == 5) {
fillData.setName(null);
}
}
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
* 修改`sheet`事件未调用的bug

Loading…
Cancel
Save