|
|
@ -3,6 +3,7 @@ package com.alibaba.excel.write.executor; |
|
|
|
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,10 +34,9 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor { |
|
|
|
protected CellData<?> converterAndSet(WriteHolder currentWriteHolder, Class<?> clazz, CellDataTypeEnum targetType, |
|
|
|
protected CellData<?> converterAndSet(WriteHolder currentWriteHolder, Class<?> clazz, CellDataTypeEnum targetType, |
|
|
|
Cell cell, Object value, |
|
|
|
Cell cell, Object value, |
|
|
|
ExcelContentProperty excelContentProperty, Head head, Integer relativeRowIndex) { |
|
|
|
ExcelContentProperty excelContentProperty, Head head, Integer relativeRowIndex) { |
|
|
|
if (value == null) { |
|
|
|
boolean needTrim = value != null && (value instanceof String && currentWriteHolder.globalConfiguration() |
|
|
|
return new CellData<>(CellDataTypeEnum.EMPTY); |
|
|
|
.getAutoTrim()); |
|
|
|
} |
|
|
|
if (needTrim) { |
|
|
|
if (value instanceof String && currentWriteHolder.globalConfiguration().getAutoTrim()) { |
|
|
|
|
|
|
|
value = ((String)value).trim(); |
|
|
|
value = ((String)value).trim(); |
|
|
|
} |
|
|
|
} |
|
|
|
CellData<?> cellData = convert(currentWriteHolder, clazz, targetType, cell, value, excelContentProperty); |
|
|
|
CellData<?> cellData = convert(currentWriteHolder, clazz, targetType, cell, value, excelContentProperty); |
|
|
@ -75,9 +75,6 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor { |
|
|
|
protected CellData<?> convert(WriteHolder currentWriteHolder, Class<?> clazz, CellDataTypeEnum targetType, |
|
|
|
protected CellData<?> convert(WriteHolder currentWriteHolder, Class<?> clazz, CellDataTypeEnum targetType, |
|
|
|
Cell cell, |
|
|
|
Cell cell, |
|
|
|
Object value, ExcelContentProperty excelContentProperty) { |
|
|
|
Object value, 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; |
|
|
@ -115,6 +112,9 @@ 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 = converter.convertToExcelData(value, excelContentProperty, currentWriteHolder); |
|
|
|
cellData = converter.convertToExcelData(value, excelContentProperty, currentWriteHolder); |
|
|
|