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 @Override
public void processRecord(XlsReadContext xlsReadContext, Record record) { public void processRecord(XlsReadContext xlsReadContext, Record record) {
NumberRecord nr = (NumberRecord)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( short dataFormat = (short)xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatIndex(
nr); nr);
cellData.setDataFormat(dataFormat); 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 // String for formula
StringRecord srec = (StringRecord)record; StringRecord srec = (StringRecord)record;
XlsReadSheetHolder xlsReadSheetHolder = xlsReadContext.xlsReadSheetHolder(); XlsReadSheetHolder xlsReadSheetHolder = xlsReadContext.xlsReadSheetHolder();
CellData tempCellData = xlsReadSheetHolder.getTempCellData(); CellData<?>tempCellData = xlsReadSheetHolder.getTempCellData();
if (tempCellData == null) { if (tempCellData == null) {
LOGGER.warn("String type formula but no value found."); LOGGER.warn("String type formula but no value found.");
return; return;

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

@ -15,7 +15,7 @@ public class CellInlineStringValueTagHandler extends AbstractCellValueTagHandler
@Override @Override
protected void setStringValue(XlsxReadContext xlsxReadContext) { protected void setStringValue(XlsxReadContext xlsxReadContext) {
// This is a special form of string // This is a special form of string
CellData tempCellData = xlsxReadContext.xlsxReadSheetHolder().getTempCellData(); CellData<?> tempCellData = xlsxReadContext.xlsxReadSheetHolder().getTempCellData();
XSSFRichTextString richTextString = new XSSFRichTextString(tempCellData.getStringValue()); XSSFRichTextString richTextString = new XSSFRichTextString(tempCellData.getStringValue());
tempCellData.setStringValue(richTextString.toString()); 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 class BuiltinFormats {
public static short GENERAL = 0;
public static final String[] BUILTIN_FORMATS_CN = { public static final String[] BUILTIN_FORMATS_CN = {
// 0 // 0
"General", "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 * @author Jiaju Zhuang
*/ */
public class AutoConverter implements Converter { public class AutoConverter implements Converter<Object> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return null; return null;
} }
@ -23,13 +23,13 @@ public class AutoConverter implements Converter {
} }
@Override @Override
public Object convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Object convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return null; return null;
} }
@Override @Override
public CellData convertToExcelData(Object value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Object value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return null; 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 * @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."); 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; package com.alibaba.excel.converters;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.alibaba.excel.enums.CellDataTypeEnum; 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. * 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 { 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 { static {
BOXING_MAP.put(int.class.getName(), Integer.class.getName()); 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()); 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 className = clazz.getName();
String boxingClassName = BOXING_MAP.get(clazz.getName()); String boxingClassName = BOXING_MAP.get(clazz.getName());
if (boxingClassName == null) { if (boxingClassName == null) {
@ -34,7 +34,11 @@ public class ConverterKeyBuild {
return boxingClassName; return boxingClassName;
} }
public static String buildKey(Class clazz, CellDataTypeEnum cellDataTypeEnum) { public static String buildKey(Class<?> clazz, CellDataTypeEnum cellDataTypeEnum) {
return buildKey(clazz) + "-" + cellDataTypeEnum.toString(); 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() { private static void initDefaultWriteConverter() {
defaultWriteConverter = MapUtils.newHashMapWithExpectedSize(20); defaultWriteConverter = MapUtils.newHashMapWithExpectedSize(40);
putWriteConverter(new BigDecimalNumberConverter()); putWriteConverter(new BigDecimalNumberConverter());
putWriteConverter(new BooleanBooleanConverter()); putWriteConverter(new BooleanBooleanConverter());
putWriteConverter(new ByteNumberConverter()); putWriteConverter(new ByteNumberConverter());
@ -114,6 +114,18 @@ public class DefaultConverterLoader {
putWriteConverter(new ByteArrayImageConverter()); putWriteConverter(new ByteArrayImageConverter());
putWriteConverter(new BoxingByteArrayImageConverter()); putWriteConverter(new BoxingByteArrayImageConverter());
putWriteConverter(new UrlImageConverter()); 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); 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 * 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> { public class BigDecimalBooleanConverter implements Converter<BigDecimal> {
@Override @Override
public Class supportJavaTypeKey() { public Class<BigDecimal> supportJavaTypeKey() {
return BigDecimal.class; return BigDecimal.class;
} }
@ -26,7 +26,7 @@ public class BigDecimalBooleanConverter implements Converter<BigDecimal> {
} }
@Override @Override
public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public BigDecimal convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) { if (cellData.getBooleanValue()) {
return BigDecimal.ONE; return BigDecimal.ONE;
@ -35,12 +35,12 @@ public class BigDecimalBooleanConverter implements Converter<BigDecimal> {
} }
@Override @Override
public CellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (BigDecimal.ONE.equals(value)) { 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> { public class BigDecimalNumberConverter implements Converter<BigDecimal> {
@Override @Override
public Class supportJavaTypeKey() { public Class<BigDecimal> supportJavaTypeKey() {
return BigDecimal.class; return BigDecimal.class;
} }
@ -28,7 +28,7 @@ public class BigDecimalNumberConverter implements Converter<BigDecimal> {
} }
@Override @Override
public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public BigDecimal convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return cellData.getNumberValue(); 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> { public class BigDecimalStringConverter implements Converter<BigDecimal> {
@Override @Override
public Class supportJavaTypeKey() { public Class<BigDecimal> supportJavaTypeKey() {
return BigDecimal.class; return BigDecimal.class;
} }
@ -28,13 +28,13 @@ public class BigDecimalStringConverter implements Converter<BigDecimal> {
} }
@Override @Override
public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public BigDecimal convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException { GlobalConfiguration globalConfiguration) throws ParseException {
return NumberUtils.parseBigDecimal(cellData.getStringValue(), contentProperty); return NumberUtils.parseBigDecimal(cellData.getStringValue(), contentProperty);
} }
@Override @Override
public CellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellDataString(value, contentProperty); 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> { public class BooleanBooleanConverter implements Converter<Boolean> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Boolean.class; return Boolean.class;
} }
@ -24,15 +24,15 @@ public class BooleanBooleanConverter implements Converter<Boolean> {
} }
@Override @Override
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Boolean convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return cellData.getBooleanValue(); return cellData.getBooleanValue();
} }
@Override @Override
public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Boolean value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { 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> { public class BooleanNumberConverter implements Converter<Boolean> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Boolean.class; return Boolean.class;
} }
@ -25,7 +25,7 @@ public class BooleanNumberConverter implements Converter<Boolean> {
} }
@Override @Override
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Boolean convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (BigDecimal.ONE.compareTo(cellData.getNumberValue()) == 0) { if (BigDecimal.ONE.compareTo(cellData.getNumberValue()) == 0) {
return Boolean.TRUE; return Boolean.TRUE;
@ -34,12 +34,12 @@ public class BooleanNumberConverter implements Converter<Boolean> {
} }
@Override @Override
public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Boolean value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (value) { 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> { public class BooleanStringConverter implements Converter<Boolean> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Boolean.class; return Boolean.class;
} }
@ -24,15 +24,15 @@ public class BooleanStringConverter implements Converter<Boolean> {
} }
@Override @Override
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Boolean convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return Boolean.valueOf(cellData.getStringValue()); return Boolean.valueOf(cellData.getStringValue());
} }
@Override @Override
public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Boolean value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { 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[]> { public class BoxingByteArrayImageConverter implements Converter<Byte[]> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Byte[].class; return Byte[].class;
} }
@ -23,19 +23,19 @@ public class BoxingByteArrayImageConverter implements Converter<Byte[]> {
} }
@Override @Override
public Byte[] convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Byte[] convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
throw new UnsupportedOperationException("Cannot convert images to byte arrays"); throw new UnsupportedOperationException("Cannot convert images to byte arrays");
} }
@Override @Override
public CellData convertToExcelData(Byte[] value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Byte[] value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
byte[] byteValue = new byte[value.length]; byte[] byteValue = new byte[value.length];
for (int i = 0; i < value.length; i++) { for (int i = 0; i < value.length; i++) {
byteValue[i] = value[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[]> { public class ByteArrayImageConverter implements Converter<byte[]> {
@Override @Override
public Class supportJavaTypeKey() { public Class<byte[]> supportJavaTypeKey() {
return byte[].class; return byte[].class;
} }
@ -23,15 +23,15 @@ public class ByteArrayImageConverter implements Converter<byte[]> {
} }
@Override @Override
public byte[] convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public byte[] convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
throw new UnsupportedOperationException("Cannot convert images to byte arrays"); throw new UnsupportedOperationException("Cannot convert images to byte arrays");
} }
@Override @Override
public CellData convertToExcelData(byte[] value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(byte[] value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { 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; private static final Byte ZERO = (byte)0;
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Byte.class; return Byte.class;
} }
@ -26,7 +26,7 @@ public class ByteBooleanConverter implements Converter<Byte> {
} }
@Override @Override
public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Byte convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) { if (cellData.getBooleanValue()) {
return ONE; return ONE;
@ -35,12 +35,12 @@ public class ByteBooleanConverter implements Converter<Byte> {
} }
@Override @Override
public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Byte value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) { 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> { public class ByteNumberConverter implements Converter<Byte> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Byte.class; return Byte.class;
} }
@ -28,7 +28,7 @@ public class ByteNumberConverter implements Converter<Byte> {
} }
@Override @Override
public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Byte convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return cellData.getNumberValue().byteValue(); 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> { public class ByteStringConverter implements Converter<Byte> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Byte.class; return Byte.class;
} }
@ -27,13 +27,13 @@ public class ByteStringConverter implements Converter<Byte> {
} }
@Override @Override
public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Byte convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException { GlobalConfiguration globalConfiguration) throws ParseException {
return NumberUtils.parseByte(cellData.getStringValue(), contentProperty); return NumberUtils.parseByte(cellData.getStringValue(), contentProperty);
} }
@Override @Override
public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Byte value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellDataString(value, contentProperty); 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 java.util.Date;
import com.alibaba.excel.converters.Converter; import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.WorkBookUtil; import com.alibaba.excel.util.WorkBookUtil;
import com.alibaba.excel.write.metadata.holder.WriteHolder; import com.alibaba.excel.write.metadata.holder.WriteHolder;
@ -19,6 +21,17 @@ public class DateDateConverter implements Converter<Date> {
return Date.class; return Date.class;
} }
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.DATE;
}
@Override
public Date convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getDateValue();
}
@Override @Override
public CellData<?> convertToExcelData(Date value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Date value, ExcelContentProperty contentProperty,
WriteHolder currentWriteHolder) throws Exception { 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> { public class DateNumberConverter implements Converter<Date> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Date.class; return Date.class;
} }
@ -29,7 +29,7 @@ public class DateNumberConverter implements Converter<Date> {
} }
@Override @Override
public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Date convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
return DateUtil.getJavaDate(cellData.getNumberValue().doubleValue(), return DateUtil.getJavaDate(cellData.getNumberValue().doubleValue(),
@ -41,13 +41,13 @@ public class DateNumberConverter implements Converter<Date> {
} }
@Override @Override
public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Date value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
return new CellData( return new CellData<>(
BigDecimal.valueOf(DateUtil.getExcelDate(value, globalConfiguration.getUse1904windowing()))); BigDecimal.valueOf(DateUtil.getExcelDate(value, globalConfiguration.getUse1904windowing())));
} else { } else {
return new CellData(BigDecimal.valueOf( return new CellData<>(BigDecimal.valueOf(
DateUtil.getExcelDate(value, contentProperty.getDateTimeFormatProperty().getUse1904windowing()))); 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> { public class DateStringConverter implements Converter<Date> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Date.class; return Date.class;
} }
@ -27,7 +27,7 @@ public class DateStringConverter implements Converter<Date> {
} }
@Override @Override
public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Date convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException { GlobalConfiguration globalConfiguration) throws ParseException {
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
return DateUtils.parseDate(cellData.getStringValue(), null); return DateUtils.parseDate(cellData.getStringValue(), null);
@ -38,12 +38,12 @@ public class DateStringConverter implements Converter<Date> {
} }
@Override @Override
public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Date value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
return new CellData(DateUtils.format(value, null)); return new CellData<>(DateUtils.format(value, null));
} else { } 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; private static final Double ZERO = 0.0;
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Double.class; return Double.class;
} }
@ -26,7 +26,7 @@ public class DoubleBooleanConverter implements Converter<Double> {
} }
@Override @Override
public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Double convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) { if (cellData.getBooleanValue()) {
return ONE; return ONE;
@ -35,12 +35,12 @@ public class DoubleBooleanConverter implements Converter<Double> {
} }
@Override @Override
public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Double value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) { 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> { public class DoubleNumberConverter implements Converter<Double> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Double.class; return Double.class;
} }
@ -28,7 +28,7 @@ public class DoubleNumberConverter implements Converter<Double> {
} }
@Override @Override
public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Double convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return cellData.getNumberValue().doubleValue(); 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> { public class DoubleStringConverter implements Converter<Double> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Double.class; return Double.class;
} }
@ -27,13 +27,13 @@ public class DoubleStringConverter implements Converter<Double> {
} }
@Override @Override
public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Double convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException { GlobalConfiguration globalConfiguration) throws ParseException {
return NumberUtils.parseDouble(cellData.getStringValue(), contentProperty); return NumberUtils.parseDouble(cellData.getStringValue(), contentProperty);
} }
@Override @Override
public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Double value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellDataString(value, contentProperty); 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> { public class FileImageConverter implements Converter<File> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return File.class; return File.class;
} }
@ -27,15 +27,15 @@ public class FileImageConverter implements Converter<File> {
} }
@Override @Override
public File convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public File convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
throw new UnsupportedOperationException("Cannot convert images to file"); throw new UnsupportedOperationException("Cannot convert images to file");
} }
@Override @Override
public CellData convertToExcelData(File value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(File value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws IOException { 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; private static final Float ZERO = (float)0.0;
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Float.class; return Float.class;
} }
@ -26,7 +26,7 @@ public class FloatBooleanConverter implements Converter<Float> {
} }
@Override @Override
public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Float convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) { if (cellData.getBooleanValue()) {
return ONE; return ONE;
@ -35,12 +35,12 @@ public class FloatBooleanConverter implements Converter<Float> {
} }
@Override @Override
public CellData convertToExcelData(Float value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Float value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) { 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> { public class FloatNumberConverter implements Converter<Float> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Float.class; return Float.class;
} }
@ -26,7 +26,7 @@ public class FloatNumberConverter implements Converter<Float> {
} }
@Override @Override
public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Float convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return cellData.getNumberValue().floatValue(); 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> { public class FloatStringConverter implements Converter<Float> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Float.class; return Float.class;
} }
@ -27,13 +27,13 @@ public class FloatStringConverter implements Converter<Float> {
} }
@Override @Override
public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Float convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException { GlobalConfiguration globalConfiguration) throws ParseException {
return NumberUtils.parseFloat(cellData.getStringValue(), contentProperty); return NumberUtils.parseFloat(cellData.getStringValue(), contentProperty);
} }
@Override @Override
public CellData convertToExcelData(Float value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Float value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellDataString(value, contentProperty); 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> { public class InputStreamImageConverter implements Converter<InputStream> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return InputStream.class; return InputStream.class;
} }
@ -27,15 +27,15 @@ public class InputStreamImageConverter implements Converter<InputStream> {
} }
@Override @Override
public InputStream convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public InputStream convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
throw new UnsupportedOperationException("Cannot convert images to input stream"); throw new UnsupportedOperationException("Cannot convert images to input stream");
} }
@Override @Override
public CellData convertToExcelData(InputStream value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(InputStream value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws IOException { 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; private static final Integer ZERO = 0;
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Integer.class; return Integer.class;
} }
@ -26,7 +26,7 @@ public class IntegerBooleanConverter implements Converter<Integer> {
} }
@Override @Override
public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Integer convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) { if (cellData.getBooleanValue()) {
return ONE; return ONE;
@ -35,12 +35,12 @@ public class IntegerBooleanConverter implements Converter<Integer> {
} }
@Override @Override
public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) { 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> { public class IntegerNumberConverter implements Converter<Integer> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Integer.class; return Integer.class;
} }
@ -26,7 +26,7 @@ public class IntegerNumberConverter implements Converter<Integer> {
} }
@Override @Override
public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Integer convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return cellData.getNumberValue().intValue(); 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> { public class IntegerStringConverter implements Converter<Integer> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Integer.class; return Integer.class;
} }
@ -27,13 +27,13 @@ public class IntegerStringConverter implements Converter<Integer> {
} }
@Override @Override
public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Integer convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException { GlobalConfiguration globalConfiguration) throws ParseException {
return NumberUtils.parseInteger(cellData.getStringValue(), contentProperty); return NumberUtils.parseInteger(cellData.getStringValue(), contentProperty);
} }
@Override @Override
public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellDataString(value, contentProperty); 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> { public class ShortStringConverter implements Converter<Short> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return Short.class; return Short.class;
} }
@ -27,13 +27,13 @@ public class ShortStringConverter implements Converter<Short> {
} }
@Override @Override
public Short convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Short convertToJavaData(CellData<?>cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException { GlobalConfiguration globalConfiguration) throws ParseException {
return NumberUtils.parseShort(cellData.getStringValue(), contentProperty); return NumberUtils.parseShort(cellData.getStringValue(), contentProperty);
} }
@Override @Override
public CellData convertToExcelData(Short value, ExcelContentProperty contentProperty, public CellData<?>convertToExcelData(Short value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellDataString(value, contentProperty); 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> { public class StringBooleanConverter implements Converter<String> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return String.class; return String.class;
} }
@ -24,15 +24,15 @@ public class StringBooleanConverter implements Converter<String> {
} }
@Override @Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public String convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return cellData.getBooleanValue().toString(); return cellData.getBooleanValue().toString();
} }
@Override @Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { 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> { public class StringErrorConverter implements Converter<String> {
@Override @Override
public Class supportJavaTypeKey() { public Class<String> supportJavaTypeKey() {
return String.class; return String.class;
} }
@ -23,15 +23,15 @@ public class StringErrorConverter implements Converter<String> {
} }
@Override @Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public String convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return cellData.getStringValue(); return cellData.getStringValue();
} }
@Override @Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { 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> { public class StringImageConverter implements Converter<String> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return String.class; return String.class;
} }
@ -27,15 +27,15 @@ public class StringImageConverter implements Converter<String> {
} }
@Override @Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public String convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
throw new UnsupportedOperationException("Cannot convert images to string"); throw new UnsupportedOperationException("Cannot convert images to string");
} }
@Override @Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws IOException { 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> { public class StringNumberConverter implements Converter<String> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return String.class; return String.class;
} }
@ -32,7 +32,7 @@ public class StringNumberConverter implements Converter<String> {
} }
@Override @Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public String convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
// If there are "DateTimeFormat", read as date // If there are "DateTimeFormat", read as date
if (contentProperty != null && contentProperty.getDateTimeFormatProperty() != null) { if (contentProperty != null && contentProperty.getDateTimeFormatProperty() != null) {
@ -55,8 +55,8 @@ public class StringNumberConverter implements Converter<String> {
} }
@Override @Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { 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> { public class StringStringConverter implements Converter<String> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return String.class; return String.class;
} }
@ -23,15 +23,15 @@ public class StringStringConverter implements Converter<String> {
} }
@Override @Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public String convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
return cellData.getStringValue(); return cellData.getStringValue();
} }
@Override @Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { 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> { public class UrlImageConverter implements Converter<URL> {
@Override @Override
public Class supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return URL.class; return URL.class;
} }
@ -29,19 +29,19 @@ public class UrlImageConverter implements Converter<URL> {
} }
@Override @Override
public URL convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public URL convertToJavaData(CellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
throw new UnsupportedOperationException("Cannot convert images to url."); throw new UnsupportedOperationException("Cannot convert images to url.");
} }
@Override @Override
public CellData convertToExcelData(URL value, ExcelContentProperty contentProperty, public CellData<?> convertToExcelData(URL value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws IOException { GlobalConfiguration globalConfiguration) throws IOException {
InputStream inputStream = null; InputStream inputStream = null;
try { try {
inputStream = value.openStream(); inputStream = value.openStream();
byte[] bytes = IoUtils.toByteArray(inputStream); byte[] bytes = IoUtils.toByteArray(inputStream);
return new CellData(bytes); return new CellData<>(bytes);
} finally { } finally {
if (inputStream != null) { if (inputStream != null) {
inputStream.close(); 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.metadata.property.ExcelContentProperty;
import com.alibaba.excel.write.builder.ExcelWriterBuilder; import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import lombok.Getter;
import lombok.Setter;
/** /**
* Data convert exception * Data convert exception
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Getter
@Setter
public class ExcelDataConvertException extends RuntimeException { public class ExcelDataConvertException extends RuntimeException {
/** /**
* NotNull. * NotNull.
@ -21,7 +26,7 @@ public class ExcelDataConvertException extends RuntimeException {
/** /**
* NotNull. * NotNull.
*/ */
private CellData cellData; private CellData<?> cellData;
/** /**
* Nullable.Only when the header is configured and when the class header is used is not null. * 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; 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; 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) { public CellData(CellDataTypeEnum type) {
if (type == null) { if (type == null) {
throw new IllegalArgumentException("Type can not be 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); return newEmptyInstance(null, null);
} }
public static CellData newEmptyInstance(Integer rowIndex, Integer columnIndex) { public static CellData<?> newEmptyInstance(Integer rowIndex, Integer columnIndex) {
CellData cellData = new CellData(CellDataTypeEnum.EMPTY); CellData<?> cellData = new CellData<>(CellDataTypeEnum.EMPTY);
cellData.setRowIndex(rowIndex); cellData.setRowIndex(rowIndex);
cellData.setColumnIndex(columnIndex); cellData.setColumnIndex(columnIndex);
return cellData; return cellData;
} }
public static CellData newInstance(Boolean booleanValue) { public static CellData<?> newInstance(Boolean booleanValue) {
return newInstance(booleanValue, null, null); return newInstance(booleanValue, null, null);
} }
public static CellData newInstance(Boolean booleanValue, Integer rowIndex, Integer columnIndex) { public static CellData<?> newInstance(Boolean booleanValue, Integer rowIndex, Integer columnIndex) {
CellData cellData = new CellData(booleanValue); CellData<?> cellData = new CellData<>(booleanValue);
cellData.setRowIndex(rowIndex); cellData.setRowIndex(rowIndex);
cellData.setColumnIndex(columnIndex); cellData.setColumnIndex(columnIndex);
return cellData; return cellData;
} }
public static CellData newInstance(String stringValue, Integer rowIndex, Integer columnIndex) { public static CellData<?> newInstance(String stringValue, Integer rowIndex, Integer columnIndex) {
CellData cellData = new CellData(stringValue); CellData<?> cellData = new CellData<>(stringValue);
cellData.setRowIndex(rowIndex); cellData.setRowIndex(rowIndex);
cellData.setColumnIndex(columnIndex); cellData.setColumnIndex(columnIndex);
return cellData; return cellData;
} }
public static CellData newInstance(BigDecimal numberValue, Integer rowIndex, Integer columnIndex) { public static CellData<?> newInstance(BigDecimal numberValue, Integer rowIndex, Integer columnIndex) {
CellData cellData = new CellData(numberValue); CellData<?> cellData = new CellData<>(numberValue);
cellData.setRowIndex(rowIndex); cellData.setRowIndex(rowIndex);
cellData.setColumnIndex(columnIndex); cellData.setColumnIndex(columnIndex);
return cellData; 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 * Current CellData
*/ */
private CellData tempCellData; private CellData<?> tempCellData;
public ReadSheetHolder(ReadSheet readSheet, ReadWorkbookHolder readWorkbookHolder) { public ReadSheetHolder(ReadSheet readSheet, ReadWorkbookHolder readWorkbookHolder) {
super(readSheet, readWorkbookHolder, readWorkbookHolder.getReadWorkbook().getConvertAllFiled()); super(readSheet, readWorkbookHolder, readWorkbookHolder.getReadWorkbook().getConvertAllFiled());
@ -135,11 +135,11 @@ public class ReadSheetHolder extends AbstractReadHolder {
this.rowIndex = rowIndex; this.rowIndex = rowIndex;
} }
public CellData getTempCellData() { public CellData<?> getTempCellData() {
return tempCellData; return tempCellData;
} }
public void setTempCellData(CellData tempCellData) { public void setTempCellData(CellData<?> tempCellData) {
this.tempCellData = tempCellData; this.tempCellData = tempCellData;
} }

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

@ -1,5 +1,8 @@
package com.alibaba.excel.util; 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.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType; 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.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment; import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import com.alibaba.excel.write.metadata.style.WriteCellStyle; import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
/** /**
* @author jipengfei * @author jipengfei
*/ */
public class StyleUtil { public class StyleUtil {
public static short XSSF_DEFAULT_STYLE = 0;
public static short HSSF_DEFAULT_STYLE = 15;
private StyleUtil() {} 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.List;
import java.util.Map; 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.context.WriteContext;
import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.Head; 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.WorkbookWriteHandler;
import com.alibaba.excel.write.handler.WriteHandler; import com.alibaba.excel.write.handler.WriteHandler;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
/** /**
* Write handler utils * Write handler utils
* *
@ -25,7 +25,6 @@ public class WriteHandlerUtils {
private WriteHandlerUtils() {} private WriteHandlerUtils() {}
public static void beforeWorkbookCreate(WriteContext writeContext) { public static void beforeWorkbookCreate(WriteContext writeContext) {
beforeWorkbookCreate(writeContext, false); beforeWorkbookCreate(writeContext, false);
} }
@ -37,7 +36,7 @@ public class WriteHandlerUtils {
} }
for (WriteHandler writeHandler : handlerList) { for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof WorkbookWriteHandler) { if (writeHandler instanceof WorkbookWriteHandler) {
((WorkbookWriteHandler) writeHandler).beforeWorkbookCreate(); ((WorkbookWriteHandler)writeHandler).beforeWorkbookCreate();
} }
} }
} }
@ -53,7 +52,7 @@ public class WriteHandlerUtils {
} }
for (WriteHandler writeHandler : handlerList) { for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof WorkbookWriteHandler) { 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) { for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof WorkbookWriteHandler) { 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) { for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof SheetWriteHandler) { if (writeHandler instanceof SheetWriteHandler) {
((SheetWriteHandler) writeHandler).beforeSheetCreate(writeContext.writeWorkbookHolder(), ((SheetWriteHandler)writeHandler).beforeSheetCreate(writeContext.writeWorkbookHolder(),
writeContext.writeSheetHolder()); writeContext.writeSheetHolder());
} }
} }
} }
public static void afterSheetCreate(WriteContext writeContext) { public static void afterSheetCreate(WriteContext writeContext) {
afterSheetCreate(writeContext, false); afterSheetCreate(writeContext, false);
} }
@ -100,7 +98,7 @@ public class WriteHandlerUtils {
} }
for (WriteHandler writeHandler : handlerList) { for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof SheetWriteHandler) { if (writeHandler instanceof SheetWriteHandler) {
((SheetWriteHandler) writeHandler).afterSheetCreate(writeContext.writeWorkbookHolder(), ((SheetWriteHandler)writeHandler).afterSheetCreate(writeContext.writeWorkbookHolder(),
writeContext.writeSheetHolder()); writeContext.writeSheetHolder());
} }
} }
@ -119,7 +117,7 @@ public class WriteHandlerUtils {
} }
for (WriteHandler writeHandler : handlerList) { for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof CellWriteHandler) { if (writeHandler instanceof CellWriteHandler) {
((CellWriteHandler) writeHandler).beforeCellCreate(writeContext.writeSheetHolder(), ((CellWriteHandler)writeHandler).beforeCellCreate(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), row, head, columnIndex, relativeRowIndex, isHead); writeContext.writeTableHolder(), row, head, columnIndex, relativeRowIndex, isHead);
} }
} }
@ -134,7 +132,7 @@ public class WriteHandlerUtils {
} }
for (WriteHandler writeHandler : handlerList) { for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof CellWriteHandler) { if (writeHandler instanceof CellWriteHandler) {
((CellWriteHandler) writeHandler).afterCellCreate(writeContext.writeSheetHolder(), ((CellWriteHandler)writeHandler).afterCellCreate(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), cell, head, relativeRowIndex, isHead); writeContext.writeTableHolder(), cell, head, relativeRowIndex, isHead);
} }
} }
@ -149,7 +147,7 @@ public class WriteHandlerUtils {
} }
for (WriteHandler writeHandler : handlerList) { for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof CellWriteHandler) { if (writeHandler instanceof CellWriteHandler) {
((CellWriteHandler) writeHandler).afterCellDataConverted(writeContext.writeSheetHolder(), ((CellWriteHandler)writeHandler).afterCellDataConverted(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), cellData, cell, head, relativeRowIndex, isHead); 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, public static void afterCellDispose(WriteContext writeContext, CellData cellData, Cell cell, Head head,
Integer relativeRowIndex, Boolean isHead) { Integer relativeRowIndex, Boolean isHead) {
List<CellData<?>> cellDataList = new ArrayList<>(); List<CellData<?>> cellDataList = new ArrayList<>();
if (cell != null) { if (cellData != null) {
cellDataList.add(cellData); cellDataList.add(cellData);
} }
afterCellDispose(writeContext, cellDataList, cell, head, relativeRowIndex, isHead); afterCellDispose(writeContext, cellDataList, cell, head, relativeRowIndex, isHead);
@ -173,7 +171,7 @@ public class WriteHandlerUtils {
} }
for (WriteHandler writeHandler : handlerList) { for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof CellWriteHandler) { if (writeHandler instanceof CellWriteHandler) {
((CellWriteHandler) writeHandler).afterCellDispose(writeContext.writeSheetHolder(), ((CellWriteHandler)writeHandler).afterCellDispose(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), cellDataList, cell, head, relativeRowIndex, isHead); writeContext.writeTableHolder(), cellDataList, cell, head, relativeRowIndex, isHead);
} }
} }
@ -190,7 +188,7 @@ public class WriteHandlerUtils {
} }
for (WriteHandler writeHandler : handlerList) { for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof RowWriteHandler) { if (writeHandler instanceof RowWriteHandler) {
((RowWriteHandler) writeHandler).beforeRowCreate(writeContext.writeSheetHolder(), ((RowWriteHandler)writeHandler).beforeRowCreate(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), rowIndex, relativeRowIndex, isHead); writeContext.writeTableHolder(), rowIndex, relativeRowIndex, isHead);
} }
} }
@ -203,7 +201,7 @@ public class WriteHandlerUtils {
} }
for (WriteHandler writeHandler : handlerList) { for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof RowWriteHandler) { if (writeHandler instanceof RowWriteHandler) {
((RowWriteHandler) writeHandler).afterRowCreate(writeContext.writeSheetHolder(), ((RowWriteHandler)writeHandler).afterRowCreate(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), row, relativeRowIndex, isHead); writeContext.writeTableHolder(), row, relativeRowIndex, isHead);
} }
} }
@ -217,7 +215,7 @@ public class WriteHandlerUtils {
} }
for (WriteHandler writeHandler : handlerList) { for (WriteHandler writeHandler : handlerList) {
if (writeHandler instanceof RowWriteHandler) { if (writeHandler instanceof RowWriteHandler) {
((RowWriteHandler) writeHandler).afterRowDispose(writeContext.writeSheetHolder(), ((RowWriteHandler)writeHandler).afterRowDispose(writeContext.writeSheetHolder(),
writeContext.writeTableHolder(), row, relativeRowIndex, isHead); 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; 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) { ExcelContentProperty excelContentProperty, Head head, Integer relativeRowIndex) {
if (value == null) { if (value == null) {
return new CellData(CellDataTypeEnum.EMPTY); return new CellData<>(CellDataTypeEnum.EMPTY);
} }
if (value instanceof String && currentWriteHolder.globalConfiguration().getAutoTrim()) { 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, targetType, cell, value, excelContentProperty);
if (cellData.getFormula() != null && cellData.getFormula()) { if (cellData.getFormula() != null && cellData.getFormula()) {
cell.setCellFormula(cellData.getFormulaValue()); 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, protected CellData<?> convert(WriteHolder currentWriteHolder, Class<?> clazz, CellDataTypeEnum targetType,
ExcelContentProperty excelContentProperty) { Cell cell,
Object value, ExcelContentProperty excelContentProperty) {
if (value == null) { if (value == null) {
return new CellData(CellDataTypeEnum.EMPTY); 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;
if (cellDataValue.getType() != null) { if (cellDataValue.getType() != null) {
return cellDataValue; return cellDataValue;
} else { } else {
@ -87,8 +89,8 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
return cellDataValue; return cellDataValue;
} }
} }
CellData cellDataReturn = doConvert(currentWriteHolder, cellDataValue.getData().getClass(), cell, CellData<?> cellDataReturn = doConvert(currentWriteHolder, cellDataValue.getData().getClass(), targetType,
cellDataValue.getData(), excelContentProperty); cell, cellDataValue.getData(), excelContentProperty);
// The formula information is subject to user input // The formula information is subject to user input
if (cellDataValue.getFormula() != null) { if (cellDataValue.getFormula() != null) {
cellDataReturn.setFormula(cellDataValue.getFormula()); cellDataReturn.setFormula(cellDataValue.getFormula());
@ -96,41 +98,40 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
} }
return cellDataReturn; 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, private CellData<?> doConvert(WriteHolder currentWriteHolder, Class<?> clazz, CellDataTypeEnum targetType,
ExcelContentProperty excelContentProperty) { Cell cell, Object value, ExcelContentProperty excelContentProperty) {
Converter converter = null; Converter converter = null;
if (excelContentProperty != null) { if (excelContentProperty != null) {
converter = excelContentProperty.getConverter(); converter = excelContentProperty.getConverter();
} }
if (converter == null) { if (converter == null) {
converter = currentWriteHolder.converterMap().get(ConverterKeyBuild.buildKey(clazz)); converter = currentWriteHolder.converterMap().get(ConverterKeyBuild.buildKey(clazz, targetType));
} }
if (converter == null) { if (converter == null) {
throw new ExcelDataConvertException(cell.getRow().getRowNum(), cell.getColumnIndex(), 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() + "."); "Can not find 'Converter' support class " + clazz.getSimpleName() + ".");
} }
CellData cellData; CellData<?> cellData;
try { try {
cellData = cellData = converter.convertToExcelData(value, excelContentProperty, currentWriteHolder);
converter.convertToExcelData(value, excelContentProperty, currentWriteHolder);
} catch (Exception e) { } catch (Exception e) {
throw new ExcelDataConvertException(cell.getRow().getRowNum(), cell.getColumnIndex(), 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); "Convert data:" + value + " error,at row:" + cell.getRow().getRowNum(), e);
} }
if (cellData == null || cellData.getType() == null) { if (cellData == null || cellData.getType() == null) {
throw new ExcelDataConvertException(cell.getRow().getRowNum(), cell.getColumnIndex(), 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()); "Convert data:" + value + " return null,at row:" + cell.getRow().getRowNum());
} }
return cellData; return cellData;
} }
private void setImageValue(CellData cellData, Cell cell) { private void setImageValue(CellData<?> cellData, Cell cell) {
Sheet sheet = cell.getSheet(); Sheet sheet = cell.getSheet();
int index = sheet.getWorkbook().addPicture(cellData.getImageValue(), HSSFWorkbook.PICTURE_TYPE_PNG); int index = sheet.getWorkbook().addPicture(cellData.getImageValue(), HSSFWorkbook.PICTURE_TYPE_PNG);
Drawing drawing = sheet.getDrawingPatriarch(); 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); WriteHandlerUtils.afterCellCreate(writeContext, cell, head, relativeRowIndex, Boolean.FALSE);
Object value = oneRowData.get(dataIndex); Object value = oneRowData.get(dataIndex);
CellData cellData = converterAndSet(writeContext.currentWriteHolder(), value == null ? null : value.getClass(), CellData cellData = converterAndSet(writeContext.currentWriteHolder(), value == null ? null : value.getClass(),
cell, value, null, head, relativeRowIndex); null, cell, value, null, head, relativeRowIndex);
writeContext.writeSheetHolder().setLastRowIndex(cellData.getRowIndex());
WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, head, relativeRowIndex, Boolean.FALSE); WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, head, relativeRowIndex, Boolean.FALSE);
} }
@ -142,8 +141,9 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
Cell cell = WorkBookUtil.createCell(row, cellIndex); Cell cell = WorkBookUtil.createCell(row, cellIndex);
WriteHandlerUtils.afterCellCreate(writeContext, cell, head, relativeRowIndex, Boolean.FALSE); WriteHandlerUtils.afterCellCreate(writeContext, cell, head, relativeRowIndex, Boolean.FALSE);
Object value = beanMap.get(name); Object value = beanMap.get(name);
CellData cellData = converterAndSet(currentWriteHolder, excelContentProperty.getField().getType(), cell, CellData<?> cellData = converterAndSet(currentWriteHolder, excelContentProperty.getField().getType(),
value, excelContentProperty, head, relativeRowIndex); null,
cell, value, excelContentProperty, head, relativeRowIndex);
WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, head, relativeRowIndex, Boolean.FALSE); WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, head, relativeRowIndex, Boolean.FALSE);
beanMapHandledSet.add(name); beanMapHandledSet.add(name);
} }
@ -167,7 +167,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
WriteHandlerUtils.beforeCellCreate(writeContext, row, null, cellIndex, relativeRowIndex, Boolean.FALSE); WriteHandlerUtils.beforeCellCreate(writeContext, row, null, cellIndex, relativeRowIndex, Boolean.FALSE);
Cell cell = WorkBookUtil.createCell(row, cellIndex); Cell cell = WorkBookUtil.createCell(row, cellIndex);
WriteHandlerUtils.afterCellCreate(writeContext, cell, null, relativeRowIndex, Boolean.FALSE); 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); value, null, null, relativeRowIndex);
WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, null, relativeRowIndex, Boolean.FALSE); 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; continue;
} }
Object value = dataMap.get(variable); Object value = dataMap.get(variable);
CellData cellData = converterAndSet(writeSheetHolder, value == null ? null : value.getClass(), cell, CellData<?> cellData = converterAndSet(writeSheetHolder, value == null ? null : value.getClass(), null,
value, fieldNameContentPropertyMap.get(variable), null, relativeRowIndex); cell, value, fieldNameContentPropertyMap.get(variable), null, relativeRowIndex);
WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, null, relativeRowIndex, Boolean.FALSE); WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, null, relativeRowIndex, Boolean.FALSE);
} else { } else {
StringBuilder cellValueBuild = new StringBuilder(); StringBuilder cellValueBuild = new StringBuilder();
@ -211,8 +211,8 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
continue; continue;
} }
Object value = dataMap.get(variable); Object value = dataMap.get(variable);
CellData cellData = convert(writeSheetHolder, value == null ? null : value.getClass(), cell, value, CellData<?> cellData = convert(writeSheetHolder, value == null ? null : value.getClass(),
fieldNameContentPropertyMap.get(variable)); CellDataTypeEnum.STRING, cell, value, fieldNameContentPropertyMap.get(variable));
cellDataList.add(cellData); cellDataList.add(cellData);
CellDataTypeEnum type = cellData.getType(); CellDataTypeEnum type = cellData.getType();
if (type != null) { 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--; headSize--;
} }
} }
Integer lastRowIndex = writeSheetHolder.getLastRowIndex();
if (lastRowIndex == null) {
lastRowIndex = 0;
}
ctWorksheet.getDimension().setRef( 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.CellData;
import com.alibaba.excel.metadata.Head; import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.util.DateUtils; import com.alibaba.excel.util.DateUtils;
import com.alibaba.excel.util.StyleUtil;
import com.alibaba.excel.write.handler.CellWriteHandler; import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder; import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
@ -46,7 +47,7 @@ public class FillDataFormatCellWriteHandler implements CellWriteHandler, Order {
} }
CellData<?> cellData = cellDataList.get(0); CellData<?> cellData = cellDataList.get(0);
CellStyle cellStyle = cell.getCellStyle(); CellStyle cellStyle = cell.getCellStyle();
if (cellStyle == null) { if (cellStyle == null || StyleUtil.isDefaultStyle(cellStyle)) {
if (cellData.getType() == CellDataTypeEnum.DATE) { if (cellData.getType() == CellDataTypeEnum.DATE) {
cell.setCellStyle(getDefaultDateCellStyle(writeSheetHolder)); 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.HashMap;
import java.util.Map; import java.util.Map;
import com.alibaba.excel.constant.BuiltinFormats;
import com.alibaba.excel.enums.HolderEnum; import com.alibaba.excel.enums.HolderEnum;
import com.alibaba.excel.exception.ExcelGenerateException; import com.alibaba.excel.exception.ExcelGenerateException;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
@ -211,7 +212,7 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
*/ */
public Short getDataFormat(String format) { public Short getDataFormat(String format) {
if (StringUtils.isEmpty(format)) { if (StringUtils.isEmpty(format)) {
return 0; return BuiltinFormats.GENERAL;
} }
Short dataFormat = dataFormatCache.get(format); Short dataFormat = dataFormatCache.get(format);
if (dataFormat != null) { 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.setContentFontProperty(FontProperty.build(contentFontStyle));
headData.setLoopMergeProperty(LoopMergeProperty.build(field.getAnnotation(ContentLoopMerge.class))); 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); WriteCellStyle headCellStyle = headCellStyle(head);
if (headCellStyle == null) { if (headCellStyle == null) {
headCellStyleCache.put(columnIndex, null); headCellStyleCache.put(columnIndex, StyleUtil.buildHeadCellStyle(workbook, null));
} else { } else {
CellStyle cellStyle = StyleUtil.buildHeadCellStyle(workbook, headCellStyle); CellStyle cellStyle = StyleUtil.buildHeadCellStyle(workbook, headCellStyle);
headCellStyleCache.put(columnIndex, cellStyle); headCellStyleCache.put(columnIndex, cellStyle);
@ -65,7 +65,7 @@ public abstract class AbstractVerticalCellStyleStrategy extends AbstractCellStyl
} }
WriteCellStyle contentCellStyle = contentCellStyle(cell, head, relativeRowIndex); WriteCellStyle contentCellStyle = contentCellStyle(cell, head, relativeRowIndex);
if (contentCellStyle == null) { if (contentCellStyle == null) {
contentCellStyleCache.put(columnIndex, null); contentCellStyleCache.put(columnIndex, StyleUtil.buildContentCellStyle(workbook, null));
} else { } else {
CellStyle cellStyle = StyleUtil.buildContentCellStyle(workbook, contentCellStyle); CellStyle cellStyle = StyleUtil.buildContentCellStyle(workbook, contentCellStyle);
contentCellStyleCache.put(columnIndex, cellStyle); 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 @Override
protected WriteCellStyle contentCellStyle(Cell cell, Head head, Integer relativeRowIndex) { protected WriteCellStyle contentCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
if (CollectionUtils.isEmpty(contentWriteCellStyleList)) { if (CollectionUtils.isEmpty(contentWriteCellStyleList)) {
return null; return new WriteCellStyle();
} }
return contentWriteCellStyleList.get(relativeRowIndex % contentWriteCellStyleList.size()); 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.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight; import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight; import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.alibaba.excel.converters.doubleconverter.DoubleStringConverter;
import lombok.Data; import lombok.Data;
@ -24,7 +23,7 @@ public class AnnotationData {
@ExcelProperty("日期") @ExcelProperty("日期")
@DateTimeFormat("yyyy年MM月dd日HH时mm分ss秒") @DateTimeFormat("yyyy年MM月dd日HH时mm分ss秒")
private Date date; private Date date;
@ExcelProperty(value = "数字", converter = DoubleStringConverter.class) @ExcelProperty(value = "数字")
@NumberFormat("#.##%") @NumberFormat("#.##%")
private Double number; private Double number;
@ExcelIgnore @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<Date> date;
private CellData<Integer> integer1; private CellData<Integer> integer1;
private Integer integer2; 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 { private List<CellDataData> data() throws Exception {
List<CellDataData> list = new ArrayList<CellDataData>(); List<CellDataData> list = new ArrayList<CellDataData>();
CellDataData cellDataData = new 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>(); CellData<Integer> integer1 = new CellData<Integer>();
integer1.setType(CellDataTypeEnum.NUMBER); integer1.setType(CellDataTypeEnum.NUMBER);
integer1.setNumberValue(BigDecimal.valueOf(2L)); 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("字符串") @ExcelProperty("字符串")
private String string; private String string;
@ExcelProperty("自定义") @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.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.DateUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -34,35 +35,40 @@ public class NoModelDataTest {
} }
@Test @Test
public void t01ReadAndWrite07() { public void t01ReadAndWrite07() throws Exception {
readAndWrite(file07, fileRepeat07); readAndWrite(file07, fileRepeat07);
} }
@Test @Test
public void t02ReadAndWrite03() { public void t02ReadAndWrite03() throws Exception {
readAndWrite(file03, fileRepeat03); 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()); EasyExcel.write(file).sheet().doWrite(data());
List<Map<Integer, String>> result = EasyExcel.read(file).headRowNumber(0).sheet().doReadSync(); List<Map<Integer, String>> result = EasyExcel.read(file).headRowNumber(0).sheet().doReadSync();
Assert.assertEquals(10, result.size()); Assert.assertEquals(10, result.size());
Map<Integer, String> data10 = result.get(9); Map<Integer, String> data10 = result.get(9);
Assert.assertEquals("string19", data10.get(0)); 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); EasyExcel.write(fileRepeat).sheet().doWrite(result);
result = EasyExcel.read(fileRepeat).headRowNumber(0).sheet().doReadSync(); result = EasyExcel.read(fileRepeat).headRowNumber(0).sheet().doReadSync();
Assert.assertEquals(10, result.size()); Assert.assertEquals(10, result.size());
data10 = result.get(9); data10 = result.get(9);
Assert.assertEquals("string19", data10.get(0)); 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() { private List<List<Object>> data() throws Exception {
List<List<String>> list = new ArrayList<>(); List<List<Object>> list = new ArrayList<>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
List<String> data = new ArrayList<>(); List<Object> data = new ArrayList<>();
data.add("string1" + i); data.add("string1" + i);
data.add("string2" + i); data.add(100 + i);
data.add("string3" + i); data.add(DateUtils.parseDate("2020-01-01 01:01:01"));
list.add(data); list.add(data);
} }
return list; 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -205,7 +206,9 @@ public class FillTest {
excelWriter.fill(new FillWrapper("data3", data()), writeSheet); excelWriter.fill(new FillWrapper("data3", data()), writeSheet);
Map<String, Object> map = new HashMap<String, Object>(); 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); excelWriter.fill(map, writeSheet);
// 别忘记关闭流 // 别忘记关闭流

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

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

Loading…
Cancel
Save