Browse Source

修改完成填充日期格式的问题

developing
Jiaju Zhuang 4 years ago
parent
commit
55551799bd
  1. 2
      src/main/java/com/alibaba/excel/analysis/v03/handlers/NumberRecordHandler.java
  2. 2
      src/main/java/com/alibaba/excel/analysis/v03/handlers/StringRecordHandler.java
  3. 2
      src/main/java/com/alibaba/excel/analysis/v07/handlers/CellInlineStringValueTagHandler.java
  4. 2
      src/main/java/com/alibaba/excel/constant/BuiltinFormats.java
  5. 8
      src/main/java/com/alibaba/excel/converters/AutoConverter.java
  6. 2
      src/main/java/com/alibaba/excel/converters/Converter.java
  7. 14
      src/main/java/com/alibaba/excel/converters/ConverterKeyBuild.java
  8. 19
      src/main/java/com/alibaba/excel/converters/DefaultConverterLoader.java
  9. 10
      src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalBooleanConverter.java
  10. 4
      src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalNumberConverter.java
  11. 6
      src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalStringConverter.java
  12. 8
      src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanBooleanConverter.java
  13. 10
      src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java
  14. 8
      src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanStringConverter.java
  15. 8
      src/main/java/com/alibaba/excel/converters/bytearray/BoxingByteArrayImageConverter.java
  16. 8
      src/main/java/com/alibaba/excel/converters/bytearray/ByteArrayImageConverter.java
  17. 10
      src/main/java/com/alibaba/excel/converters/byteconverter/ByteBooleanConverter.java
  18. 4
      src/main/java/com/alibaba/excel/converters/byteconverter/ByteNumberConverter.java
  19. 6
      src/main/java/com/alibaba/excel/converters/byteconverter/ByteStringConverter.java
  20. 13
      src/main/java/com/alibaba/excel/converters/date/DateDateConverter.java
  21. 10
      src/main/java/com/alibaba/excel/converters/date/DateNumberConverter.java
  22. 10
      src/main/java/com/alibaba/excel/converters/date/DateStringConverter.java
  23. 10
      src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleBooleanConverter.java
  24. 4
      src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleNumberConverter.java
  25. 6
      src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleStringConverter.java
  26. 8
      src/main/java/com/alibaba/excel/converters/file/FileImageConverter.java
  27. 10
      src/main/java/com/alibaba/excel/converters/floatconverter/FloatBooleanConverter.java
  28. 4
      src/main/java/com/alibaba/excel/converters/floatconverter/FloatNumberConverter.java
  29. 6
      src/main/java/com/alibaba/excel/converters/floatconverter/FloatStringConverter.java
  30. 8
      src/main/java/com/alibaba/excel/converters/inputstream/InputStreamImageConverter.java
  31. 10
      src/main/java/com/alibaba/excel/converters/integer/IntegerBooleanConverter.java
  32. 4
      src/main/java/com/alibaba/excel/converters/integer/IntegerNumberConverter.java
  33. 6
      src/main/java/com/alibaba/excel/converters/integer/IntegerStringConverter.java
  34. 6
      src/main/java/com/alibaba/excel/converters/shortconverter/ShortStringConverter.java
  35. 8
      src/main/java/com/alibaba/excel/converters/string/StringBooleanConverter.java
  36. 8
      src/main/java/com/alibaba/excel/converters/string/StringErrorConverter.java
  37. 8
      src/main/java/com/alibaba/excel/converters/string/StringImageConverter.java
  38. 8
      src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java
  39. 8
      src/main/java/com/alibaba/excel/converters/string/StringStringConverter.java
  40. 8
      src/main/java/com/alibaba/excel/converters/url/UrlImageConverter.java
  41. 38
      src/main/java/com/alibaba/excel/exception/ExcelDataConvertException.java
  42. 30
      src/main/java/com/alibaba/excel/metadata/CellData.java
  43. 6
      src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java
  44. 20
      src/main/java/com/alibaba/excel/util/StyleUtil.java
  45. 34
      src/main/java/com/alibaba/excel/util/WriteHandlerUtils.java
  46. 41
      src/main/java/com/alibaba/excel/write/executor/AbstractExcelWriteExecutor.java
  47. 10
      src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java
  48. 8
      src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java
  49. 7
      src/main/java/com/alibaba/excel/write/handler/impl/DimensionWorkbookWriteHandler.java
  50. 3
      src/main/java/com/alibaba/excel/write/handler/impl/FillDataFormatCellWriteHandler.java
  51. 3
      src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java
  52. 8
      src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java
  53. 4
      src/main/java/com/alibaba/excel/write/style/AbstractVerticalCellStyleStrategy.java
  54. 2
      src/main/java/com/alibaba/excel/write/style/HorizontalCellStyleStrategy.java
  55. 3
      src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationData.java
  56. 2
      src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataData.java
  57. 2
      src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java
  58. 2
      src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterData.java
  59. 22
      src/test/java/com/alibaba/easyexcel/test/core/nomodel/NoModelDataTest.java
  60. 5
      src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java
  61. 2
      src/test/java/com/alibaba/easyexcel/test/temp/poi/TestCell.java

2
src/main/java/com/alibaba/excel/analysis/v03/handlers/NumberRecordHandler.java

@ -21,7 +21,7 @@ public class NumberRecordHandler extends AbstractXlsRecordHandler implements Ign
@Override
public void processRecord(XlsReadContext xlsReadContext, Record record) {
NumberRecord nr = (NumberRecord)record;
CellData cellData = CellData.newInstance(BigDecimal.valueOf(nr.getValue()), nr.getRow(), (int)nr.getColumn());
CellData<?>cellData = CellData.newInstance(BigDecimal.valueOf(nr.getValue()), nr.getRow(), (int)nr.getColumn());
short dataFormat = (short)xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatIndex(
nr);
cellData.setDataFormat(dataFormat);

2
src/main/java/com/alibaba/excel/analysis/v03/handlers/StringRecordHandler.java

@ -23,7 +23,7 @@ public class StringRecordHandler extends AbstractXlsRecordHandler implements Ign
// String for formula
StringRecord srec = (StringRecord)record;
XlsReadSheetHolder xlsReadSheetHolder = xlsReadContext.xlsReadSheetHolder();
CellData tempCellData = xlsReadSheetHolder.getTempCellData();
CellData<?>tempCellData = xlsReadSheetHolder.getTempCellData();
if (tempCellData == null) {
LOGGER.warn("String type formula but no value found.");
return;

2
src/main/java/com/alibaba/excel/analysis/v07/handlers/CellInlineStringValueTagHandler.java

@ -15,7 +15,7 @@ public class CellInlineStringValueTagHandler extends AbstractCellValueTagHandler
@Override
protected void setStringValue(XlsxReadContext xlsxReadContext) {
// This is a special form of string
CellData tempCellData = xlsxReadContext.xlsxReadSheetHolder().getTempCellData();
CellData<?> tempCellData = xlsxReadContext.xlsxReadSheetHolder().getTempCellData();
XSSFRichTextString richTextString = new XSSFRichTextString(tempCellData.getStringValue());
tempCellData.setStringValue(richTextString.toString());
}

2
src/main/java/com/alibaba/excel/constant/BuiltinFormats.java

@ -17,6 +17,8 @@ import java.util.Locale;
**/
public class BuiltinFormats {
public static short GENERAL = 0;
public static final String[] BUILTIN_FORMATS_CN = {
// 0
"General",

8
src/main/java/com/alibaba/excel/converters/AutoConverter.java

@ -10,10 +10,10 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
*
* @author Jiaju Zhuang
*/
public class AutoConverter implements Converter {
public class AutoConverter implements Converter<Object> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return null;
}
@ -23,13 +23,13 @@ public class AutoConverter implements Converter {
}
@Override
public Object convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Object convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return null;
}
@Override
public CellData convertToExcelData(Object value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Object value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return null;
}

2
src/main/java/com/alibaba/excel/converters/Converter.java

@ -22,7 +22,7 @@ public interface Converter<T> {
*
* @return Support for Java class
*/
default Class<T> supportJavaTypeKey() {
default Class<?> supportJavaTypeKey() {
throw new UnsupportedOperationException("The current operation is not supported by the current converter.");
}

14
src/main/java/com/alibaba/excel/converters/ConverterKeyBuild.java

@ -1,9 +1,9 @@
package com.alibaba.excel.converters;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.util.MapUtils;
/**
* Converter unique key.Consider that you can just use class as the key.
@ -12,7 +12,7 @@ import com.alibaba.excel.enums.CellDataTypeEnum;
*/
public class ConverterKeyBuild {
private static final Map<String, String> BOXING_MAP = new HashMap<String, String>(16);
private static final Map<String, String> BOXING_MAP = MapUtils.newHashMap();
static {
BOXING_MAP.put(int.class.getName(), Integer.class.getName());
@ -25,7 +25,7 @@ public class ConverterKeyBuild {
BOXING_MAP.put(boolean.class.getName(), Boolean.class.getName());
}
public static String buildKey(Class clazz) {
public static String buildKey(Class<?> clazz) {
String className = clazz.getName();
String boxingClassName = BOXING_MAP.get(clazz.getName());
if (boxingClassName == null) {
@ -34,7 +34,11 @@ public class ConverterKeyBuild {
return boxingClassName;
}
public static String buildKey(Class clazz, CellDataTypeEnum cellDataTypeEnum) {
return buildKey(clazz) + "-" + cellDataTypeEnum.toString();
public static String buildKey(Class<?> clazz, CellDataTypeEnum cellDataTypeEnum) {
String key = buildKey(clazz);
if (cellDataTypeEnum == null) {
return key;
}
return key + "-" + cellDataTypeEnum.toString();
}
}

19
src/main/java/com/alibaba/excel/converters/DefaultConverterLoader.java

@ -98,7 +98,7 @@ public class DefaultConverterLoader {
}
private static void initDefaultWriteConverter() {
defaultWriteConverter = MapUtils.newHashMapWithExpectedSize(20);
defaultWriteConverter = MapUtils.newHashMapWithExpectedSize(40);
putWriteConverter(new BigDecimalNumberConverter());
putWriteConverter(new BooleanBooleanConverter());
putWriteConverter(new ByteNumberConverter());
@ -114,6 +114,18 @@ public class DefaultConverterLoader {
putWriteConverter(new ByteArrayImageConverter());
putWriteConverter(new BoxingByteArrayImageConverter());
putWriteConverter(new UrlImageConverter());
// In some cases, it must be converted to string
putWriteStringConverter(new BigDecimalStringConverter());
putWriteStringConverter(new BooleanStringConverter());
putWriteStringConverter(new ByteStringConverter());
putWriteStringConverter(new DateStringConverter());
putWriteStringConverter(new DoubleStringConverter());
putWriteStringConverter(new FloatStringConverter());
putWriteStringConverter(new IntegerStringConverter());
putWriteStringConverter(new LongStringConverter());
putWriteStringConverter(new ShortStringConverter());
putWriteStringConverter(new StringStringConverter());
}
/**
@ -129,6 +141,11 @@ public class DefaultConverterLoader {
defaultWriteConverter.put(ConverterKeyBuild.buildKey(converter.supportJavaTypeKey()), converter);
}
private static void putWriteStringConverter(Converter<?> converter) {
defaultWriteConverter.put(
ConverterKeyBuild.buildKey(converter.supportJavaTypeKey(), converter.supportExcelTypeKey()), converter);
}
/**
* Load default read converter
*

10
src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalBooleanConverter.java

@ -16,7 +16,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
public class BigDecimalBooleanConverter implements Converter<BigDecimal> {
@Override
public Class supportJavaTypeKey() {
public Class<BigDecimal> supportJavaTypeKey() {
return BigDecimal.class;
}
@ -26,7 +26,7 @@ public class BigDecimalBooleanConverter implements Converter<BigDecimal> {
}
@Override
public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public BigDecimal convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) {
return BigDecimal.ONE;
@ -35,12 +35,12 @@ public class BigDecimalBooleanConverter implements Converter<BigDecimal> {
}
@Override
public CellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (BigDecimal.ONE.equals(value)) {
return new CellData(Boolean.TRUE);
return new CellData<>(Boolean.TRUE);
}
return new CellData(Boolean.FALSE);
return new CellData<>(Boolean.FALSE);
}
}

4
src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalNumberConverter.java

@ -18,7 +18,7 @@ import com.alibaba.excel.write.metadata.holder.WriteHolder;
public class BigDecimalNumberConverter implements Converter<BigDecimal> {
@Override
public Class supportJavaTypeKey() {
public Class<BigDecimal> supportJavaTypeKey() {
return BigDecimal.class;
}
@ -28,7 +28,7 @@ public class BigDecimalNumberConverter implements Converter<BigDecimal> {
}
@Override
public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public BigDecimal convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getNumberValue();
}

6
src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalStringConverter.java

@ -18,7 +18,7 @@ import com.alibaba.excel.util.NumberUtils;
public class BigDecimalStringConverter implements Converter<BigDecimal> {
@Override
public Class supportJavaTypeKey() {
public Class<BigDecimal> supportJavaTypeKey() {
return BigDecimal.class;
}
@ -28,13 +28,13 @@ public class BigDecimalStringConverter implements Converter<BigDecimal> {
}
@Override
public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public BigDecimal convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException {
return NumberUtils.parseBigDecimal(cellData.getStringValue(), contentProperty);
}
@Override
public CellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellDataString(value, contentProperty);
}

8
src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanBooleanConverter.java

@ -14,7 +14,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
public class BooleanBooleanConverter implements Converter<Boolean> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Boolean.class;
}
@ -24,15 +24,15 @@ public class BooleanBooleanConverter implements Converter<Boolean> {
}
@Override
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Boolean convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getBooleanValue();
}
@Override
public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Boolean value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value);
return new CellData<>(value);
}
}

10
src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java

@ -15,7 +15,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
*/
public class BooleanNumberConverter implements Converter<Boolean> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Boolean.class;
}
@ -25,7 +25,7 @@ public class BooleanNumberConverter implements Converter<Boolean> {
}
@Override
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Boolean convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (BigDecimal.ONE.compareTo(cellData.getNumberValue()) == 0) {
return Boolean.TRUE;
@ -34,12 +34,12 @@ public class BooleanNumberConverter implements Converter<Boolean> {
}
@Override
public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Boolean value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (value) {
return new CellData(BigDecimal.ONE);
return new CellData<>(BigDecimal.ONE);
}
return new CellData(BigDecimal.ZERO);
return new CellData<>(BigDecimal.ZERO);
}
}

8
src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanStringConverter.java

@ -14,7 +14,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
public class BooleanStringConverter implements Converter<Boolean> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Boolean.class;
}
@ -24,15 +24,15 @@ public class BooleanStringConverter implements Converter<Boolean> {
}
@Override
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Boolean convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return Boolean.valueOf(cellData.getStringValue());
}
@Override
public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Boolean value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value.toString());
return new CellData<>(value.toString());
}
}

8
src/main/java/com/alibaba/excel/converters/bytearray/BoxingByteArrayImageConverter.java

@ -13,7 +13,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
*/
public class BoxingByteArrayImageConverter implements Converter<Byte[]> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Byte[].class;
}
@ -23,19 +23,19 @@ public class BoxingByteArrayImageConverter implements Converter<Byte[]> {
}
@Override
public Byte[] convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Byte[] convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
throw new UnsupportedOperationException("Cannot convert images to byte arrays");
}
@Override
public CellData convertToExcelData(Byte[] value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Byte[] value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
byte[] byteValue = new byte[value.length];
for (int i = 0; i < value.length; i++) {
byteValue[i] = value[i];
}
return new CellData(byteValue);
return new CellData<>(byteValue);
}
}

8
src/main/java/com/alibaba/excel/converters/bytearray/ByteArrayImageConverter.java

@ -13,7 +13,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
*/
public class ByteArrayImageConverter implements Converter<byte[]> {
@Override
public Class supportJavaTypeKey() {
public Class<byte[]> supportJavaTypeKey() {
return byte[].class;
}
@ -23,15 +23,15 @@ public class ByteArrayImageConverter implements Converter<byte[]> {
}
@Override
public byte[] convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public byte[] convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
throw new UnsupportedOperationException("Cannot convert images to byte arrays");
}
@Override
public CellData convertToExcelData(byte[] value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(byte[] value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value);
return new CellData<>(value);
}
}

10
src/main/java/com/alibaba/excel/converters/byteconverter/ByteBooleanConverter.java

@ -16,7 +16,7 @@ public class ByteBooleanConverter implements Converter<Byte> {
private static final Byte ZERO = (byte)0;
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Byte.class;
}
@ -26,7 +26,7 @@ public class ByteBooleanConverter implements Converter<Byte> {
}
@Override
public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Byte convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) {
return ONE;
@ -35,12 +35,12 @@ public class ByteBooleanConverter implements Converter<Byte> {
}
@Override
public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Byte value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) {
return new CellData(Boolean.TRUE);
return new CellData<>(Boolean.TRUE);
}
return new CellData(Boolean.FALSE);
return new CellData<>(Boolean.FALSE);
}
}

4
src/main/java/com/alibaba/excel/converters/byteconverter/ByteNumberConverter.java

@ -18,7 +18,7 @@ import com.alibaba.excel.write.metadata.holder.WriteHolder;
public class ByteNumberConverter implements Converter<Byte> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Byte.class;
}
@ -28,7 +28,7 @@ public class ByteNumberConverter implements Converter<Byte> {
}
@Override
public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Byte convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getNumberValue().byteValue();
}

6
src/main/java/com/alibaba/excel/converters/byteconverter/ByteStringConverter.java

@ -17,7 +17,7 @@ import com.alibaba.excel.util.NumberUtils;
public class ByteStringConverter implements Converter<Byte> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Byte.class;
}
@ -27,13 +27,13 @@ public class ByteStringConverter implements Converter<Byte> {
}
@Override
public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Byte convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException {
return NumberUtils.parseByte(cellData.getStringValue(), contentProperty);
}
@Override
public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Byte value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellDataString(value, contentProperty);
}

13
src/main/java/com/alibaba/excel/converters/date/DateDateConverter.java

@ -3,7 +3,9 @@ package com.alibaba.excel.converters.date;
import java.util.Date;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.WorkBookUtil;
import com.alibaba.excel.write.metadata.holder.WriteHolder;
@ -19,6 +21,17 @@ public class DateDateConverter implements Converter<Date> {
return Date.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.DATE;
}
@Override
public Date convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getDateValue();
}
@Override
public CellData<?> convertToExcelData(Date value, ExcelContentProperty contentProperty,
WriteHolder currentWriteHolder) throws Exception {

10
src/main/java/com/alibaba/excel/converters/date/DateNumberConverter.java

@ -19,7 +19,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
public class DateNumberConverter implements Converter<Date> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Date.class;
}
@ -29,7 +29,7 @@ public class DateNumberConverter implements Converter<Date> {
}
@Override
public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Date convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
return DateUtil.getJavaDate(cellData.getNumberValue().doubleValue(),
@ -41,13 +41,13 @@ public class DateNumberConverter implements Converter<Date> {
}
@Override
public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Date value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
return new CellData(
return new CellData<>(
BigDecimal.valueOf(DateUtil.getExcelDate(value, globalConfiguration.getUse1904windowing())));
} else {
return new CellData(BigDecimal.valueOf(
return new CellData<>(BigDecimal.valueOf(
DateUtil.getExcelDate(value, contentProperty.getDateTimeFormatProperty().getUse1904windowing())));
}
}

10
src/main/java/com/alibaba/excel/converters/date/DateStringConverter.java

@ -17,7 +17,7 @@ import com.alibaba.excel.util.DateUtils;
*/
public class DateStringConverter implements Converter<Date> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Date.class;
}
@ -27,7 +27,7 @@ public class DateStringConverter implements Converter<Date> {
}
@Override
public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Date convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException {
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
return DateUtils.parseDate(cellData.getStringValue(), null);
@ -38,12 +38,12 @@ public class DateStringConverter implements Converter<Date> {
}
@Override
public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Date value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
return new CellData(DateUtils.format(value, null));
return new CellData<>(DateUtils.format(value, null));
} else {
return new CellData(DateUtils.format(value, contentProperty.getDateTimeFormatProperty().getFormat()));
return new CellData<>(DateUtils.format(value, contentProperty.getDateTimeFormatProperty().getFormat()));
}
}
}

10
src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleBooleanConverter.java

@ -16,7 +16,7 @@ public class DoubleBooleanConverter implements Converter<Double> {
private static final Double ZERO = 0.0;
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Double.class;
}
@ -26,7 +26,7 @@ public class DoubleBooleanConverter implements Converter<Double> {
}
@Override
public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Double convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) {
return ONE;
@ -35,12 +35,12 @@ public class DoubleBooleanConverter implements Converter<Double> {
}
@Override
public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Double value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) {
return new CellData(Boolean.TRUE);
return new CellData<>(Boolean.TRUE);
}
return new CellData(Boolean.FALSE);
return new CellData<>(Boolean.FALSE);
}
}

4
src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleNumberConverter.java

@ -18,7 +18,7 @@ import com.alibaba.excel.write.metadata.holder.WriteHolder;
public class DoubleNumberConverter implements Converter<Double> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Double.class;
}
@ -28,7 +28,7 @@ public class DoubleNumberConverter implements Converter<Double> {
}
@Override
public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Double convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getNumberValue().doubleValue();
}

6
src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleStringConverter.java

@ -17,7 +17,7 @@ import com.alibaba.excel.util.NumberUtils;
public class DoubleStringConverter implements Converter<Double> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Double.class;
}
@ -27,13 +27,13 @@ public class DoubleStringConverter implements Converter<Double> {
}
@Override
public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Double convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException {
return NumberUtils.parseDouble(cellData.getStringValue(), contentProperty);
}
@Override
public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Double value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellDataString(value, contentProperty);
}

8
src/main/java/com/alibaba/excel/converters/file/FileImageConverter.java

@ -17,7 +17,7 @@ import com.alibaba.excel.util.FileUtils;
*/
public class FileImageConverter implements Converter<File> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return File.class;
}
@ -27,15 +27,15 @@ public class FileImageConverter implements Converter<File> {
}
@Override
public File convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public File convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
throw new UnsupportedOperationException("Cannot convert images to file");
}
@Override
public CellData convertToExcelData(File value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(File value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws IOException {
return new CellData(FileUtils.readFileToByteArray(value));
return new CellData<>(FileUtils.readFileToByteArray(value));
}
}

10
src/main/java/com/alibaba/excel/converters/floatconverter/FloatBooleanConverter.java

@ -16,7 +16,7 @@ public class FloatBooleanConverter implements Converter<Float> {
private static final Float ZERO = (float)0.0;
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Float.class;
}
@ -26,7 +26,7 @@ public class FloatBooleanConverter implements Converter<Float> {
}
@Override
public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Float convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) {
return ONE;
@ -35,12 +35,12 @@ public class FloatBooleanConverter implements Converter<Float> {
}
@Override
public CellData convertToExcelData(Float value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Float value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) {
return new CellData(Boolean.TRUE);
return new CellData<>(Boolean.TRUE);
}
return new CellData(Boolean.FALSE);
return new CellData<>(Boolean.FALSE);
}
}

4
src/main/java/com/alibaba/excel/converters/floatconverter/FloatNumberConverter.java

@ -16,7 +16,7 @@ import com.alibaba.excel.write.metadata.holder.WriteHolder;
public class FloatNumberConverter implements Converter<Float> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Float.class;
}
@ -26,7 +26,7 @@ public class FloatNumberConverter implements Converter<Float> {
}
@Override
public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Float convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getNumberValue().floatValue();
}

6
src/main/java/com/alibaba/excel/converters/floatconverter/FloatStringConverter.java

@ -17,7 +17,7 @@ import com.alibaba.excel.util.NumberUtils;
public class FloatStringConverter implements Converter<Float> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Float.class;
}
@ -27,13 +27,13 @@ public class FloatStringConverter implements Converter<Float> {
}
@Override
public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Float convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException {
return NumberUtils.parseFloat(cellData.getStringValue(), contentProperty);
}
@Override
public CellData convertToExcelData(Float value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Float value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellDataString(value, contentProperty);
}

8
src/main/java/com/alibaba/excel/converters/inputstream/InputStreamImageConverter.java

@ -17,7 +17,7 @@ import com.alibaba.excel.util.IoUtils;
*/
public class InputStreamImageConverter implements Converter<InputStream> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return InputStream.class;
}
@ -27,15 +27,15 @@ public class InputStreamImageConverter implements Converter<InputStream> {
}
@Override
public InputStream convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public InputStream convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
throw new UnsupportedOperationException("Cannot convert images to input stream");
}
@Override
public CellData convertToExcelData(InputStream value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(InputStream value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws IOException {
return new CellData(IoUtils.toByteArray(value));
return new CellData<>(IoUtils.toByteArray(value));
}
}

10
src/main/java/com/alibaba/excel/converters/integer/IntegerBooleanConverter.java

@ -16,7 +16,7 @@ public class IntegerBooleanConverter implements Converter<Integer> {
private static final Integer ZERO = 0;
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Integer.class;
}
@ -26,7 +26,7 @@ public class IntegerBooleanConverter implements Converter<Integer> {
}
@Override
public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Integer convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) {
return ONE;
@ -35,12 +35,12 @@ public class IntegerBooleanConverter implements Converter<Integer> {
}
@Override
public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) {
return new CellData(Boolean.TRUE);
return new CellData<>(Boolean.TRUE);
}
return new CellData(Boolean.FALSE);
return new CellData<>(Boolean.FALSE);
}
}

4
src/main/java/com/alibaba/excel/converters/integer/IntegerNumberConverter.java

@ -16,7 +16,7 @@ import com.alibaba.excel.write.metadata.holder.WriteHolder;
public class IntegerNumberConverter implements Converter<Integer> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Integer.class;
}
@ -26,7 +26,7 @@ public class IntegerNumberConverter implements Converter<Integer> {
}
@Override
public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Integer convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getNumberValue().intValue();
}

6
src/main/java/com/alibaba/excel/converters/integer/IntegerStringConverter.java

@ -17,7 +17,7 @@ import com.alibaba.excel.util.NumberUtils;
public class IntegerStringConverter implements Converter<Integer> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Integer.class;
}
@ -27,13 +27,13 @@ public class IntegerStringConverter implements Converter<Integer> {
}
@Override
public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Integer convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException {
return NumberUtils.parseInteger(cellData.getStringValue(), contentProperty);
}
@Override
public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellDataString(value, contentProperty);
}

6
src/main/java/com/alibaba/excel/converters/shortconverter/ShortStringConverter.java

@ -17,7 +17,7 @@ import com.alibaba.excel.util.NumberUtils;
public class ShortStringConverter implements Converter<Short> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return Short.class;
}
@ -27,13 +27,13 @@ public class ShortStringConverter implements Converter<Short> {
}
@Override
public Short convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public Short convertToJavaData(CellData<?>cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException {
return NumberUtils.parseShort(cellData.getStringValue(), contentProperty);
}
@Override
public CellData convertToExcelData(Short value, ExcelContentProperty contentProperty,
public CellData<?>convertToExcelData(Short value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellDataString(value, contentProperty);
}

8
src/main/java/com/alibaba/excel/converters/string/StringBooleanConverter.java

@ -14,7 +14,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
public class StringBooleanConverter implements Converter<String> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return String.class;
}
@ -24,15 +24,15 @@ public class StringBooleanConverter implements Converter<String> {
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public String convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getBooleanValue().toString();
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(Boolean.valueOf(value));
return new CellData<>(Boolean.valueOf(value));
}
}

8
src/main/java/com/alibaba/excel/converters/string/StringErrorConverter.java

@ -13,7 +13,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
*/
public class StringErrorConverter implements Converter<String> {
@Override
public Class supportJavaTypeKey() {
public Class<String> supportJavaTypeKey() {
return String.class;
}
@ -23,15 +23,15 @@ public class StringErrorConverter implements Converter<String> {
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public String convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getStringValue();
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(CellDataTypeEnum.ERROR, value);
return new CellData<>(CellDataTypeEnum.ERROR, value);
}
}

8
src/main/java/com/alibaba/excel/converters/string/StringImageConverter.java

@ -17,7 +17,7 @@ import com.alibaba.excel.util.FileUtils;
*/
public class StringImageConverter implements Converter<String> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return String.class;
}
@ -27,15 +27,15 @@ public class StringImageConverter implements Converter<String> {
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public String convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
throw new UnsupportedOperationException("Cannot convert images to string");
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws IOException {
return new CellData(FileUtils.readFileToByteArray(new File(value)));
return new CellData<>(FileUtils.readFileToByteArray(new File(value)));
}
}

8
src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java

@ -22,7 +22,7 @@ import com.alibaba.excel.util.StringUtils;
public class StringNumberConverter implements Converter<String> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return String.class;
}
@ -32,7 +32,7 @@ public class StringNumberConverter implements Converter<String> {
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public String convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
// If there are "DateTimeFormat", read as date
if (contentProperty != null && contentProperty.getDateTimeFormatProperty() != null) {
@ -55,8 +55,8 @@ public class StringNumberConverter implements Converter<String> {
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(new BigDecimal(value));
return new CellData<>(new BigDecimal(value));
}
}

8
src/main/java/com/alibaba/excel/converters/string/StringStringConverter.java

@ -13,7 +13,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
*/
public class StringStringConverter implements Converter<String> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return String.class;
}
@ -23,15 +23,15 @@ public class StringStringConverter implements Converter<String> {
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public String convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getStringValue();
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value);
return new CellData<>(value);
}
}

8
src/main/java/com/alibaba/excel/converters/url/UrlImageConverter.java

@ -19,7 +19,7 @@ import com.alibaba.excel.util.IoUtils;
*/
public class UrlImageConverter implements Converter<URL> {
@Override
public Class supportJavaTypeKey() {
public Class<?> supportJavaTypeKey() {
return URL.class;
}
@ -29,19 +29,19 @@ public class UrlImageConverter implements Converter<URL> {
}
@Override
public URL convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
public URL convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
throw new UnsupportedOperationException("Cannot convert images to url.");
}
@Override
public CellData convertToExcelData(URL value, ExcelContentProperty contentProperty,
public CellData<?> convertToExcelData(URL value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws IOException {
InputStream inputStream = null;
try {
inputStream = value.openStream();
byte[] bytes = IoUtils.toByteArray(inputStream);
return new CellData(bytes);
return new CellData<>(bytes);
} finally {
if (inputStream != null) {
inputStream.close();

38
src/main/java/com/alibaba/excel/exception/ExcelDataConvertException.java

@ -4,11 +4,16 @@ import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import lombok.Getter;
import lombok.Setter;
/**
* Data convert exception
*
* @author Jiaju Zhuang
*/
@Getter
@Setter
public class ExcelDataConvertException extends RuntimeException {
/**
* NotNull.
@ -21,7 +26,7 @@ public class ExcelDataConvertException extends RuntimeException {
/**
* NotNull.
*/
private CellData cellData;
private CellData<?> cellData;
/**
* Nullable.Only when the header is configured and when the class header is used is not null.
*
@ -47,35 +52,4 @@ public class ExcelDataConvertException extends RuntimeException {
this.excelContentProperty = excelContentProperty;
}
public Integer getRowIndex() {
return rowIndex;
}
public void setRowIndex(Integer rowIndex) {
this.rowIndex = rowIndex;
}
public Integer getColumnIndex() {
return columnIndex;
}
public void setColumnIndex(Integer columnIndex) {
this.columnIndex = columnIndex;
}
public ExcelContentProperty getExcelContentProperty() {
return excelContentProperty;
}
public void setExcelContentProperty(ExcelContentProperty excelContentProperty) {
this.excelContentProperty = excelContentProperty;
}
public CellData getCellData() {
return cellData;
}
public void setCellData(CellData cellData) {
this.cellData = cellData;
}
}

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

@ -122,6 +122,16 @@ public class CellData<T> extends AbstractCell {
this.formula = Boolean.FALSE;
}
public CellData(Date dateValue) {
if (dateValue == null) {
throw new IllegalArgumentException("DateValue can not be null");
}
this.type = CellDataTypeEnum.DATE;
this.dateValue = dateValue;
this.formula = Boolean.FALSE;
}
public CellData(CellDataTypeEnum type) {
if (type == null) {
throw new IllegalArgumentException("Type can not be null");
@ -158,37 +168,37 @@ public class CellData<T> extends AbstractCell {
}
}
public static CellData newEmptyInstance() {
public static CellData<?> newEmptyInstance() {
return newEmptyInstance(null, null);
}
public static CellData newEmptyInstance(Integer rowIndex, Integer columnIndex) {
CellData cellData = new CellData(CellDataTypeEnum.EMPTY);
public static CellData<?> newEmptyInstance(Integer rowIndex, Integer columnIndex) {
CellData<?> cellData = new CellData<>(CellDataTypeEnum.EMPTY);
cellData.setRowIndex(rowIndex);
cellData.setColumnIndex(columnIndex);
return cellData;
}
public static CellData newInstance(Boolean booleanValue) {
public static CellData<?> newInstance(Boolean booleanValue) {
return newInstance(booleanValue, null, null);
}
public static CellData newInstance(Boolean booleanValue, Integer rowIndex, Integer columnIndex) {
CellData cellData = new CellData(booleanValue);
public static CellData<?> newInstance(Boolean booleanValue, Integer rowIndex, Integer columnIndex) {
CellData<?> cellData = new CellData<>(booleanValue);
cellData.setRowIndex(rowIndex);
cellData.setColumnIndex(columnIndex);
return cellData;
}
public static CellData newInstance(String stringValue, Integer rowIndex, Integer columnIndex) {
CellData cellData = new CellData(stringValue);
public static CellData<?> newInstance(String stringValue, Integer rowIndex, Integer columnIndex) {
CellData<?> cellData = new CellData<>(stringValue);
cellData.setRowIndex(rowIndex);
cellData.setColumnIndex(columnIndex);
return cellData;
}
public static CellData newInstance(BigDecimal numberValue, Integer rowIndex, Integer columnIndex) {
CellData cellData = new CellData(numberValue);
public static CellData<?> newInstance(BigDecimal numberValue, Integer rowIndex, Integer columnIndex) {
CellData<?> cellData = new CellData<>(numberValue);
cellData.setRowIndex(rowIndex);
cellData.setColumnIndex(columnIndex);
return cellData;

6
src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java

@ -51,7 +51,7 @@ public class ReadSheetHolder extends AbstractReadHolder {
/**
* Current CellData
*/
private CellData tempCellData;
private CellData<?> tempCellData;
public ReadSheetHolder(ReadSheet readSheet, ReadWorkbookHolder readWorkbookHolder) {
super(readSheet, readWorkbookHolder, readWorkbookHolder.getReadWorkbook().getConvertAllFiled());
@ -135,11 +135,11 @@ public class ReadSheetHolder extends AbstractReadHolder {
this.rowIndex = rowIndex;
}
public CellData getTempCellData() {
public CellData<?> getTempCellData() {
return tempCellData;
}
public void setTempCellData(CellData tempCellData) {
public void setTempCellData(CellData<?> tempCellData) {
this.tempCellData = tempCellData;
}

20
src/main/java/com/alibaba/excel/util/StyleUtil.java

@ -1,5 +1,8 @@
package com.alibaba.excel.util;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
@ -8,15 +11,17 @@ import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
/**
* @author jipengfei
*/
public class StyleUtil {
public static short XSSF_DEFAULT_STYLE = 0;
public static short HSSF_DEFAULT_STYLE = 15;
private StyleUtil() {}
/**
@ -183,4 +188,13 @@ public class StyleUtil {
}
}
public static boolean isDefaultStyle(CellStyle cellStyle) {
if (cellStyle == null) {
return true;
}
if (cellStyle instanceof XSSFCellStyle) {
return cellStyle.getIndex() == XSSF_DEFAULT_STYLE;
}
return cellStyle.getIndex() == HSSF_DEFAULT_STYLE;
}
}

34
src/main/java/com/alibaba/excel/util/WriteHandlerUtils.java

@ -4,9 +4,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import com.alibaba.excel.context.WriteContext;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.Head;
@ -16,6 +13,9 @@ import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.handler.WorkbookWriteHandler;
import com.alibaba.excel.write.handler.WriteHandler;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
/**
* Write handler utils
*
@ -25,7 +25,6 @@ public class WriteHandlerUtils {
private WriteHandlerUtils() {}
public static void beforeWorkbookCreate(WriteContext writeContext) {
beforeWorkbookCreate(writeContext, false);
}
@ -37,7 +36,7 @@ public class WriteHandlerUtils {
}
for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof WorkbookWriteHandler) {
((WorkbookWriteHandler) writeHandler).beforeWorkbookCreate();
((WorkbookWriteHandler)writeHandler).beforeWorkbookCreate();
}
}
}
@ -53,7 +52,7 @@ public class WriteHandlerUtils {
}
for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof WorkbookWriteHandler) {
((WorkbookWriteHandler) writeHandler).afterWorkbookCreate(writeContext.writeWorkbookHolder());
((WorkbookWriteHandler)writeHandler).afterWorkbookCreate(writeContext.writeWorkbookHolder());
}
}
}
@ -66,7 +65,7 @@ public class WriteHandlerUtils {
}
for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof WorkbookWriteHandler) {
((WorkbookWriteHandler) writeHandler).afterWorkbookDispose(writeContext.writeWorkbookHolder());
((WorkbookWriteHandler)writeHandler).afterWorkbookDispose(writeContext.writeWorkbookHolder());
}
}
}
@ -82,13 +81,12 @@ public class WriteHandlerUtils {
}
for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof SheetWriteHandler) {
((SheetWriteHandler) writeHandler).beforeSheetCreate(writeContext.writeWorkbookHolder(),
((SheetWriteHandler)writeHandler).beforeSheetCreate(writeContext.writeWorkbookHolder(),
writeContext.writeSheetHolder());
}
}
}
public static void afterSheetCreate(WriteContext writeContext) {
afterSheetCreate(writeContext, false);
}
@ -100,7 +98,7 @@ public class WriteHandlerUtils {
}
for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof SheetWriteHandler) {
((SheetWriteHandler) writeHandler).afterSheetCreate(writeContext.writeWorkbookHolder(),
((SheetWriteHandler)writeHandler).afterSheetCreate(writeContext.writeWorkbookHolder(),
writeContext.writeSheetHolder());
}
}
@ -119,7 +117,7 @@ public class WriteHandlerUtils {
}
for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof CellWriteHandler) {
((CellWriteHandler) writeHandler).beforeCellCreate(writeContext.writeSheetHolder(),
((CellWriteHandler)writeHandler).beforeCellCreate(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), row, head, columnIndex, relativeRowIndex, isHead);
}
}
@ -134,7 +132,7 @@ public class WriteHandlerUtils {
}
for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof CellWriteHandler) {
((CellWriteHandler) writeHandler).afterCellCreate(writeContext.writeSheetHolder(),
((CellWriteHandler)writeHandler).afterCellCreate(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), cell, head, relativeRowIndex, isHead);
}
}
@ -149,7 +147,7 @@ public class WriteHandlerUtils {
}
for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof CellWriteHandler) {
((CellWriteHandler) writeHandler).afterCellDataConverted(writeContext.writeSheetHolder(),
((CellWriteHandler)writeHandler).afterCellDataConverted(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), cellData, cell, head, relativeRowIndex, isHead);
}
}
@ -158,7 +156,7 @@ public class WriteHandlerUtils {
public static void afterCellDispose(WriteContext writeContext, CellData cellData, Cell cell, Head head,
Integer relativeRowIndex, Boolean isHead) {
List<CellData<?>> cellDataList = new ArrayList<>();
if (cell != null) {
if (cellData != null) {
cellDataList.add(cellData);
}
afterCellDispose(writeContext, cellDataList, cell, head, relativeRowIndex, isHead);
@ -173,7 +171,7 @@ public class WriteHandlerUtils {
}
for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof CellWriteHandler) {
((CellWriteHandler) writeHandler).afterCellDispose(writeContext.writeSheetHolder(),
((CellWriteHandler)writeHandler).afterCellDispose(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), cellDataList, cell, head, relativeRowIndex, isHead);
}
}
@ -190,7 +188,7 @@ public class WriteHandlerUtils {
}
for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof RowWriteHandler) {
((RowWriteHandler) writeHandler).beforeRowCreate(writeContext.writeSheetHolder(),
((RowWriteHandler)writeHandler).beforeRowCreate(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), rowIndex, relativeRowIndex, isHead);
}
}
@ -203,7 +201,7 @@ public class WriteHandlerUtils {
}
for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof RowWriteHandler) {
((RowWriteHandler) writeHandler).afterRowCreate(writeContext.writeSheetHolder(),
((RowWriteHandler)writeHandler).afterRowCreate(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), row, relativeRowIndex, isHead);
}
}
@ -217,7 +215,7 @@ public class WriteHandlerUtils {
}
for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof RowWriteHandler) {
((RowWriteHandler) writeHandler).afterRowDispose(writeContext.writeSheetHolder(),
((RowWriteHandler)writeHandler).afterRowDispose(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), row, relativeRowIndex, isHead);
}
}

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

@ -30,15 +30,16 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
this.writeContext = writeContext;
}
protected CellData converterAndSet(WriteHolder currentWriteHolder, Class clazz, Cell cell, Object value,
protected CellData<?> converterAndSet(WriteHolder currentWriteHolder, Class<?> clazz, CellDataTypeEnum targetType,
Cell cell, Object value,
ExcelContentProperty excelContentProperty, Head head, Integer relativeRowIndex) {
if (value == null) {
return new CellData(CellDataTypeEnum.EMPTY);
return new CellData<>(CellDataTypeEnum.EMPTY);
}
if (value instanceof String && currentWriteHolder.globalConfiguration().getAutoTrim()) {
value = ((String)value).trim();
}
CellData cellData = convert(currentWriteHolder, clazz, cell, value, excelContentProperty);
CellData<?> cellData = convert(currentWriteHolder, clazz, targetType, cell, value, excelContentProperty);
if (cellData.getFormula() != null && cellData.getFormula()) {
cell.setCellFormula(cellData.getFormulaValue());
}
@ -71,14 +72,15 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
}
}
protected CellData convert(WriteHolder currentWriteHolder, Class clazz, Cell cell, Object value,
ExcelContentProperty excelContentProperty) {
protected CellData<?> convert(WriteHolder currentWriteHolder, Class<?> clazz, CellDataTypeEnum targetType,
Cell cell,
Object value, ExcelContentProperty excelContentProperty) {
if (value == null) {
return new CellData(CellDataTypeEnum.EMPTY);
return new CellData<>(CellDataTypeEnum.EMPTY);
}
// This means that the user has defined the data.
if (value instanceof CellData) {
CellData cellDataValue = (CellData)value;
CellData<?> cellDataValue = (CellData<?>)value;
if (cellDataValue.getType() != null) {
return cellDataValue;
} else {
@ -87,8 +89,8 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
return cellDataValue;
}
}
CellData cellDataReturn = doConvert(currentWriteHolder, cellDataValue.getData().getClass(), cell,
cellDataValue.getData(), excelContentProperty);
CellData<?> cellDataReturn = doConvert(currentWriteHolder, cellDataValue.getData().getClass(), targetType,
cell, cellDataValue.getData(), excelContentProperty);
// The formula information is subject to user input
if (cellDataValue.getFormula() != null) {
cellDataReturn.setFormula(cellDataValue.getFormula());
@ -96,41 +98,40 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
}
return cellDataReturn;
}
return doConvert(currentWriteHolder, clazz, cell, value, excelContentProperty);
return doConvert(currentWriteHolder, clazz, targetType, cell, value, excelContentProperty);
}
private CellData doConvert(WriteHolder currentWriteHolder, Class clazz, Cell cell, Object value,
ExcelContentProperty excelContentProperty) {
private CellData<?> doConvert(WriteHolder currentWriteHolder, Class<?> clazz, CellDataTypeEnum targetType,
Cell cell, Object value, ExcelContentProperty excelContentProperty) {
Converter converter = null;
if (excelContentProperty != null) {
converter = excelContentProperty.getConverter();
}
if (converter == null) {
converter = currentWriteHolder.converterMap().get(ConverterKeyBuild.buildKey(clazz));
converter = currentWriteHolder.converterMap().get(ConverterKeyBuild.buildKey(clazz, targetType));
}
if (converter == null) {
throw new ExcelDataConvertException(cell.getRow().getRowNum(), cell.getColumnIndex(),
new CellData(CellDataTypeEnum.EMPTY), excelContentProperty,
new CellData<>(CellDataTypeEnum.EMPTY), excelContentProperty,
"Can not find 'Converter' support class " + clazz.getSimpleName() + ".");
}
CellData cellData;
CellData<?> cellData;
try {
cellData =
converter.convertToExcelData(value, excelContentProperty, currentWriteHolder);
cellData = converter.convertToExcelData(value, excelContentProperty, currentWriteHolder);
} catch (Exception e) {
throw new ExcelDataConvertException(cell.getRow().getRowNum(), cell.getColumnIndex(),
new CellData(CellDataTypeEnum.EMPTY), excelContentProperty,
new CellData<>(CellDataTypeEnum.EMPTY), excelContentProperty,
"Convert data:" + value + " error,at row:" + cell.getRow().getRowNum(), e);
}
if (cellData == null || cellData.getType() == null) {
throw new ExcelDataConvertException(cell.getRow().getRowNum(), cell.getColumnIndex(),
new CellData(CellDataTypeEnum.EMPTY), excelContentProperty,
new CellData<>(CellDataTypeEnum.EMPTY), excelContentProperty,
"Convert data:" + value + " return null,at row:" + cell.getRow().getRowNum());
}
return cellData;
}
private void setImageValue(CellData cellData, Cell cell) {
private void setImageValue(CellData<?> cellData, Cell cell) {
Sheet sheet = cell.getSheet();
int index = sheet.getWorkbook().addPicture(cellData.getImageValue(), HSSFWorkbook.PICTURE_TYPE_PNG);
Drawing drawing = sheet.getDrawingPatriarch();

10
src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java

@ -114,8 +114,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
WriteHandlerUtils.afterCellCreate(writeContext, cell, head, relativeRowIndex, Boolean.FALSE);
Object value = oneRowData.get(dataIndex);
CellData cellData = converterAndSet(writeContext.currentWriteHolder(), value == null ? null : value.getClass(),
cell, value, null, head, relativeRowIndex);
writeContext.writeSheetHolder().setLastRowIndex(cellData.getRowIndex());
null, cell, value, null, head, relativeRowIndex);
WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, head, relativeRowIndex, Boolean.FALSE);
}
@ -142,8 +141,9 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
Cell cell = WorkBookUtil.createCell(row, cellIndex);
WriteHandlerUtils.afterCellCreate(writeContext, cell, head, relativeRowIndex, Boolean.FALSE);
Object value = beanMap.get(name);
CellData cellData = converterAndSet(currentWriteHolder, excelContentProperty.getField().getType(), cell,
value, excelContentProperty, head, relativeRowIndex);
CellData<?> cellData = converterAndSet(currentWriteHolder, excelContentProperty.getField().getType(),
null,
cell, value, excelContentProperty, head, relativeRowIndex);
WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, head, relativeRowIndex, Boolean.FALSE);
beanMapHandledSet.add(name);
}
@ -167,7 +167,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
WriteHandlerUtils.beforeCellCreate(writeContext, row, null, cellIndex, relativeRowIndex, Boolean.FALSE);
Cell cell = WorkBookUtil.createCell(row, cellIndex);
WriteHandlerUtils.afterCellCreate(writeContext, cell, null, relativeRowIndex, Boolean.FALSE);
CellData cellData = converterAndSet(currentWriteHolder, value == null ? null : value.getClass(), cell,
CellData<?> cellData = converterAndSet(currentWriteHolder, value == null ? null : value.getClass(), null, cell,
value, null, null, relativeRowIndex);
WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, null, relativeRowIndex, Boolean.FALSE);
}

8
src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java

@ -198,8 +198,8 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
continue;
}
Object value = dataMap.get(variable);
CellData cellData = converterAndSet(writeSheetHolder, value == null ? null : value.getClass(), cell,
value, fieldNameContentPropertyMap.get(variable), null, relativeRowIndex);
CellData<?> cellData = converterAndSet(writeSheetHolder, value == null ? null : value.getClass(), null,
cell, value, fieldNameContentPropertyMap.get(variable), null, relativeRowIndex);
WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, null, relativeRowIndex, Boolean.FALSE);
} else {
StringBuilder cellValueBuild = new StringBuilder();
@ -211,8 +211,8 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
continue;
}
Object value = dataMap.get(variable);
CellData cellData = convert(writeSheetHolder, value == null ? null : value.getClass(), cell, value,
fieldNameContentPropertyMap.get(variable));
CellData<?> cellData = convert(writeSheetHolder, value == null ? null : value.getClass(),
CellDataTypeEnum.STRING, cell, value, fieldNameContentPropertyMap.get(variable));
cellDataList.add(cellData);
CellDataTypeEnum type = cellData.getType();
if (type != null) {

7
src/main/java/com/alibaba/excel/write/handler/impl/DimensionWorkbookWriteHandler.java

@ -69,8 +69,13 @@ public class DimensionWorkbookWriteHandler implements WorkbookWriteHandler {
headSize--;
}
}
Integer lastRowIndex = writeSheetHolder.getLastRowIndex();
if (lastRowIndex == null) {
lastRowIndex = 0;
}
ctWorksheet.getDimension().setRef(
"A1:" + CellReference.convertNumToColString(headSize) + (writeSheetHolder.getLastRowIndex() + 1));
"A1:" + CellReference.convertNumToColString(headSize) + (lastRowIndex + 1));
}
}
}

3
src/main/java/com/alibaba/excel/write/handler/impl/FillDataFormatCellWriteHandler.java

@ -10,6 +10,7 @@ import com.alibaba.excel.event.Order;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.util.DateUtils;
import com.alibaba.excel.util.StyleUtil;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
@ -46,7 +47,7 @@ public class FillDataFormatCellWriteHandler implements CellWriteHandler, Order {
}
CellData<?> cellData = cellDataList.get(0);
CellStyle cellStyle = cell.getCellStyle();
if (cellStyle == null) {
if (cellStyle == null || StyleUtil.isDefaultStyle(cellStyle)) {
if (cellData.getType() == CellDataTypeEnum.DATE) {
cell.setCellStyle(getDefaultDateCellStyle(writeSheetHolder));
}

3
src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java

@ -10,6 +10,7 @@ import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.excel.constant.BuiltinFormats;
import com.alibaba.excel.enums.HolderEnum;
import com.alibaba.excel.exception.ExcelGenerateException;
import com.alibaba.excel.support.ExcelTypeEnum;
@ -211,7 +212,7 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
*/
public Short getDataFormat(String format) {
if (StringUtils.isEmpty(format)) {
return 0;
return BuiltinFormats.GENERAL;
}
Short dataFormat = dataFormatCache.get(format);
if (dataFormat != null) {

8
src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java

@ -102,14 +102,6 @@ public class ExcelWriteHeadProperty extends ExcelHeadProperty {
headData.setContentFontProperty(FontProperty.build(contentFontStyle));
headData.setLoopMergeProperty(LoopMergeProperty.build(field.getAnnotation(ContentLoopMerge.class)));
// If have @NumberFormat, 'NumberStringConverter' is specified by default
if (excelContentPropertyData.getConverter() == null) {
NumberFormat numberFormat = field.getAnnotation(NumberFormat.class);
if (numberFormat != null) {
excelContentPropertyData.setConverter(DefaultConverterLoader.loadAllConverter()
.get(ConverterKeyBuild.buildKey(field.getType(), CellDataTypeEnum.STRING)));
}
}
}
}

4
src/main/java/com/alibaba/excel/write/style/AbstractVerticalCellStyleStrategy.java

@ -42,7 +42,7 @@ public abstract class AbstractVerticalCellStyleStrategy extends AbstractCellStyl
}
WriteCellStyle headCellStyle = headCellStyle(head);
if (headCellStyle == null) {
headCellStyleCache.put(columnIndex, null);
headCellStyleCache.put(columnIndex, StyleUtil.buildHeadCellStyle(workbook, null));
} else {
CellStyle cellStyle = StyleUtil.buildHeadCellStyle(workbook, headCellStyle);
headCellStyleCache.put(columnIndex, cellStyle);
@ -65,7 +65,7 @@ public abstract class AbstractVerticalCellStyleStrategy extends AbstractCellStyl
}
WriteCellStyle contentCellStyle = contentCellStyle(cell, head, relativeRowIndex);
if (contentCellStyle == null) {
contentCellStyleCache.put(columnIndex, null);
contentCellStyleCache.put(columnIndex, StyleUtil.buildContentCellStyle(workbook, null));
} else {
CellStyle cellStyle = StyleUtil.buildContentCellStyle(workbook, contentCellStyle);
contentCellStyleCache.put(columnIndex, cellStyle);

2
src/main/java/com/alibaba/excel/write/style/HorizontalCellStyleStrategy.java

@ -39,7 +39,7 @@ public class HorizontalCellStyleStrategy extends AbstractVerticalCellStyleStrate
@Override
protected WriteCellStyle contentCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
if (CollectionUtils.isEmpty(contentWriteCellStyleList)) {
return null;
return new WriteCellStyle();
}
return contentWriteCellStyleList.get(relativeRowIndex % contentWriteCellStyleList.size());
}

3
src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationData.java

@ -9,7 +9,6 @@ import com.alibaba.excel.annotation.format.NumberFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.alibaba.excel.converters.doubleconverter.DoubleStringConverter;
import lombok.Data;
@ -24,7 +23,7 @@ public class AnnotationData {
@ExcelProperty("日期")
@DateTimeFormat("yyyy年MM月dd日HH时mm分ss秒")
private Date date;
@ExcelProperty(value = "数字", converter = DoubleStringConverter.class)
@ExcelProperty(value = "数字")
@NumberFormat("#.##%")
private Double number;
@ExcelIgnore

2
src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataData.java

@ -17,5 +17,5 @@ public class CellDataData {
private CellData<Date> date;
private CellData<Integer> integer1;
private Integer integer2;
private CellData formulaValue;
private CellData<?> formulaValue;
}

2
src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java

@ -55,7 +55,7 @@ public class CellDataDataTest {
private List<CellDataData> data() throws Exception {
List<CellDataData> list = new ArrayList<CellDataData>();
CellDataData cellDataData = new CellDataData();
cellDataData.setDate(new CellData<Date>(DateUtils.parseDate("2020-01-01 01:01:01")));
cellDataData.setDate(new CellData<>(DateUtils.parseDate("2020-01-01 01:01:01")));
CellData<Integer> integer1 = new CellData<Integer>();
integer1.setType(CellDataTypeEnum.NUMBER);
integer1.setNumberValue(BigDecimal.valueOf(2L));

2
src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterData.java

@ -34,5 +34,5 @@ public class ConverterData {
@ExcelProperty("字符串")
private String string;
@ExcelProperty("自定义")
private CellData cellData;
private CellData<?> cellData;
}

22
src/test/java/com/alibaba/easyexcel/test/core/nomodel/NoModelDataTest.java

@ -7,6 +7,7 @@ import java.util.Map;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.DateUtils;
import org.junit.Assert;
import org.junit.BeforeClass;
@ -34,35 +35,40 @@ public class NoModelDataTest {
}
@Test
public void t01ReadAndWrite07() {
public void t01ReadAndWrite07() throws Exception {
readAndWrite(file07, fileRepeat07);
}
@Test
public void t02ReadAndWrite03() {
public void t02ReadAndWrite03() throws Exception {
readAndWrite(file03, fileRepeat03);
}
private void readAndWrite(File file, File fileRepeat) {
private void readAndWrite(File file, File fileRepeat) throws Exception {
EasyExcel.write(file).sheet().doWrite(data());
List<Map<Integer, String>> result = EasyExcel.read(file).headRowNumber(0).sheet().doReadSync();
Assert.assertEquals(10, result.size());
Map<Integer, String> data10 = result.get(9);
Assert.assertEquals("string19", data10.get(0));
Assert.assertEquals("109", data10.get(1));
Assert.assertEquals("2020-01-01 01:01:01", data10.get(2));
EasyExcel.write(fileRepeat).sheet().doWrite(result);
result = EasyExcel.read(fileRepeat).headRowNumber(0).sheet().doReadSync();
Assert.assertEquals(10, result.size());
data10 = result.get(9);
Assert.assertEquals("string19", data10.get(0));
Assert.assertEquals("109", data10.get(1));
Assert.assertEquals("2020-01-01 01:01:01", data10.get(2));
}
private List<List<String>> data() {
List<List<String>> list = new ArrayList<>();
private List<List<Object>> data() throws Exception {
List<List<Object>> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
List<String> data = new ArrayList<>();
List<Object> data = new ArrayList<>();
data.add("string1" + i);
data.add("string2" + i);
data.add("string3" + i);
data.add(100 + i);
data.add(DateUtils.parseDate("2020-01-01 01:01:01"));
list.add(data);
}
return list;

5
src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java

@ -2,6 +2,7 @@ package com.alibaba.easyexcel.test.demo.fill;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -205,7 +206,9 @@ public class FillTest {
excelWriter.fill(new FillWrapper("data3", data()), writeSheet);
Map<String, Object> map = new HashMap<String, Object>();
map.put("date", "2019年10月9日13:28:28");
//map.put("date", "2019年10月9日13:28:28");
map.put("date", new Date());
excelWriter.fill(map, writeSheet);
// 别忘记关闭流

2
src/test/java/com/alibaba/easyexcel/test/temp/poi/TestCell.java

@ -13,6 +13,6 @@ import lombok.Data;
**/
@Data
public class TestCell {
private CellData c1;
private CellData<?> c1;
private CellData<List<String>> c2;
}

Loading…
Cancel
Save