Skip to content

Commit

Permalink
修改填充数据空数据的bug #1274
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuangjiaju committed Apr 27, 2020
1 parent 34cd600 commit fba1f72
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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;
Expand All @@ -33,10 +32,11 @@ public AbstractExcelWriteExecutor(WriteContext writeContext) {

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) {
value = ((String) value).trim();
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);
if (cellData.getFormula() != null && cellData.getFormula()) {
Expand Down Expand Up @@ -70,6 +70,9 @@ protected CellData converterAndSet(WriteHolder currentWriteHolder, Class clazz,

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;
Expand Down Expand Up @@ -107,9 +110,6 @@ private CellData doConvert(WriteHolder currentWriteHolder, Class clazz, Cell cel
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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ private void compositeFill(File file, File template) {
excelWriter.finish();

List<Object> list = EasyExcel.read(file).ignoreEmptyRow(false).sheet().headRowNumber(0).doReadSync();
Map<String, String> map0 = (Map<String, String>)list.get(0);
Map<String, String> map0 = (Map<String, String>) list.get(0);
Assert.assertEquals("张三", map0.get(21));
Map<String, String> map27 = (Map<String, String>)list.get(27);
Map<String, String> map27 = (Map<String, String>) list.get(27);
Assert.assertEquals("张三", map27.get(0));
Map<String, String> map29 = (Map<String, String>)list.get(29);
Map<String, String> map29 = (Map<String, String>) list.get(29);
Assert.assertEquals("张三", map29.get(3));
}

Expand All @@ -168,7 +168,7 @@ private void horizontalFill(File file, File template) {

List<Object> list = EasyExcel.read(file).sheet().headRowNumber(0).doReadSync();
Assert.assertEquals(list.size(), 5L);
Map<String, String> map0 = (Map<String, String>)list.get(0);
Map<String, String> map0 = (Map<String, String>) list.get(0);
Assert.assertEquals("张三", map0.get(2));
}

Expand All @@ -185,7 +185,7 @@ private void complexFill(File file, File template) {
excelWriter.finish();
List<Object> list = EasyExcel.read(file).sheet().headRowNumber(3).doReadSync();
Assert.assertEquals(list.size(), 21L);
Map<String, String> map19 = (Map<String, String>)list.get(19);
Map<String, String> map19 = (Map<String, String>) list.get(19);
Assert.assertEquals("张三", map19.get(0));
}

Expand All @@ -203,6 +203,9 @@ private List<FillData> data() {
list.add(fillData);
fillData.setName("张三");
fillData.setNumber(5.2);
if (i == 5) {
fillData.setName(null);
}
}
return list;
}
Expand Down
4 changes: 4 additions & 0 deletions update.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.2.3
* 修改填充数据空数据的bug [Issue #1274](https://github.com/alibaba/easyexcel/issues/1274)
* 回退自定义转换器入参为空

# 2.2.2
* 修改`sheet`事件未调用的bug

Expand Down

0 comments on commit fba1f72

Please sign in to comment.