Browse Source

优化读写的写法,方便读写

bugfix
zhuangjiaju 5 years ago
parent
commit
a9f12c078b
  1. 7
      pom.xml
  2. 2
      src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java
  3. 15
      src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java
  4. 10
      src/main/java/com/alibaba/excel/annotation/ExcelProperty.java
  5. 36
      src/main/java/com/alibaba/excel/converters/AutoConverter.java
  6. 9
      src/main/java/com/alibaba/excel/converters/Converter.java
  7. 7
      src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalBooleanConverter.java
  8. 7
      src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalNumberConverter.java
  9. 7
      src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalStringConverter.java
  10. 7
      src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanBooleanConverter.java
  11. 7
      src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java
  12. 7
      src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanStringConverter.java
  13. 7
      src/main/java/com/alibaba/excel/converters/byteconverter/ByteBooleanConverter.java
  14. 7
      src/main/java/com/alibaba/excel/converters/byteconverter/ByteNumberConverter.java
  15. 7
      src/main/java/com/alibaba/excel/converters/byteconverter/ByteStringConverter.java
  16. 13
      src/main/java/com/alibaba/excel/converters/date/DateNumberConverter.java
  17. 7
      src/main/java/com/alibaba/excel/converters/date/DateStringConverter.java
  18. 7
      src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleBooleanConverter.java
  19. 7
      src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleNumberConverter.java
  20. 7
      src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleStringConverter.java
  21. 7
      src/main/java/com/alibaba/excel/converters/floatconverter/FloatBooleanConverter.java
  22. 7
      src/main/java/com/alibaba/excel/converters/floatconverter/FloatNumberConverter.java
  23. 7
      src/main/java/com/alibaba/excel/converters/floatconverter/FloatStringConverter.java
  24. 7
      src/main/java/com/alibaba/excel/converters/integer/IntegerBooleanConverter.java
  25. 7
      src/main/java/com/alibaba/excel/converters/integer/IntegerNumberConverter.java
  26. 7
      src/main/java/com/alibaba/excel/converters/integer/IntegerStringConverter.java
  27. 7
      src/main/java/com/alibaba/excel/converters/longconverter/LongBooleanConverter.java
  28. 7
      src/main/java/com/alibaba/excel/converters/longconverter/LongNumberConverter.java
  29. 7
      src/main/java/com/alibaba/excel/converters/longconverter/LongStringConverter.java
  30. 7
      src/main/java/com/alibaba/excel/converters/shortconverter/ShortBooleanConverter.java
  31. 7
      src/main/java/com/alibaba/excel/converters/shortconverter/ShortNumberConverter.java
  32. 7
      src/main/java/com/alibaba/excel/converters/shortconverter/ShortStringConverter.java
  33. 7
      src/main/java/com/alibaba/excel/converters/string/StringBooleanConverter.java
  34. 7
      src/main/java/com/alibaba/excel/converters/string/StringErrorConverter.java
  35. 7
      src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java
  36. 7
      src/main/java/com/alibaba/excel/converters/string/StringStringConverter.java
  37. 2
      src/main/java/com/alibaba/excel/metadata/AbstractHolder.java
  38. 36
      src/main/java/com/alibaba/excel/metadata/ConfigurationHolder.java
  39. 24
      src/main/java/com/alibaba/excel/metadata/Holder.java
  40. 21
      src/main/java/com/alibaba/excel/metadata/property/ExcelContentProperty.java
  41. 14
      src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java
  42. 1
      src/main/java/com/alibaba/excel/parameter/GenerateParam.java
  43. 20
      src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java
  44. 1
      src/main/java/com/alibaba/excel/read/listener/ReadListenerRegistryCenter.java
  45. 11
      src/main/java/com/alibaba/excel/read/listener/event/AnalysisFinishEvent.java
  46. 2
      src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java
  47. 4
      src/main/java/com/alibaba/excel/read/metadata/holder/ReadHolder.java
  48. 9
      src/main/java/com/alibaba/excel/read/metadata/holder/ReadRowHolder.java
  49. 13
      src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java
  50. 4
      src/main/java/com/alibaba/excel/write/metadata/holder/WriteHolder.java

7
pom.xml

@ -56,13 +56,6 @@
</licenses>
<dependencies>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>

2
src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java

@ -83,6 +83,8 @@ public class XlsxSaxAnalyser implements ExcelExecutor {
CTWorkbookPr prefix = wb.getWorkbookPr();
if (prefix != null && prefix.getDate1904()) {
readWorkbookHolder.getGlobalConfiguration().setUse1904windowing(Boolean.TRUE);
} else {
readWorkbookHolder.getGlobalConfiguration().setUse1904windowing(Boolean.FALSE);
}
}

15
src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java

@ -21,6 +21,7 @@ import com.alibaba.excel.read.metadata.holder.ReadRowHolder;
import com.alibaba.excel.util.BooleanUtils;
import com.alibaba.excel.util.PositionUtils;
import com.alibaba.excel.util.StringUtils;
/**
* Cell Handler
*
@ -84,8 +85,12 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder
ensureSize();
// Have to go "sharedStrings.xml" and get it
if (currentCellData.getType() == CellDataTypeEnum.STRING) {
currentCellData.setStringValue(analysisContext.readWorkbookHolder().getReadCache()
.get(Integer.valueOf(currentCellData.getStringValue())));
String stringValue = analysisContext.readWorkbookHolder().getReadCache()
.get(Integer.valueOf(currentCellData.getStringValue()));
if (stringValue != null && analysisContext.currentReadHolder().globalConfiguration().getAutoTrim()) {
stringValue = stringValue.trim();
}
currentCellData.setStringValue(stringValue);
}
curRowContent[curCol] = currentCellData;
}
@ -93,7 +98,11 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder
if (CELL_INLINE_STRING_VALUE_TAG.equals(name)) {
ensureSize();
XSSFRichTextString richTextString = new XSSFRichTextString(currentCellData.getStringValue());
currentCellData.setStringValue(richTextString.toString());
String stringValue = richTextString.toString();
if (stringValue != null && analysisContext.currentReadHolder().globalConfiguration().getAutoTrim()) {
stringValue = stringValue.trim();
}
currentCellData.setStringValue(stringValue);
curRowContent[curCol] = currentCellData;
}
}

10
src/main/java/com/alibaba/excel/annotation/ExcelProperty.java

@ -6,6 +6,9 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.alibaba.excel.converters.AutoConverter;
import com.alibaba.excel.converters.Converter;
/**
* @author jipengfei
*/
@ -33,6 +36,13 @@ public @interface ExcelProperty {
*/
int index() default -1;
/**
* Force the current field to use this converter.
*
* @return
*/
Class<? extends Converter> converter() default AutoConverter.class;
/**
*
* default @see com.alibaba.excel.util.TypeUtil if default is not meet you can set format

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

@ -0,0 +1,36 @@
package com.alibaba.excel.converters;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
* An empty converter.It's automatically converted by type.
*
* @author zhuangjiaju
*/
public class AutoConverter implements Converter {
@Override
public Class supportJavaTypeKey() {
return null;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return null;
}
@Override
public Object convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return null;
}
@Override
public CellData convertToExcelData(Object value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return null;
}
}

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

@ -2,6 +2,7 @@ package com.alibaba.excel.converters;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
@ -33,18 +34,22 @@ public interface Converter<T> {
*
* @param cellData
* @param contentProperty
* @param globalConfiguration
* @return
* @throws Exception
*/
T convertToJavaData(@NotNull CellData cellData, @Nullable ExcelContentProperty contentProperty) throws Exception;
T convertToJavaData(@NotNull CellData cellData, @Nullable ExcelContentProperty contentProperty,
@NotNull GlobalConfiguration globalConfiguration) throws Exception;
/**
* Convert Java objects to excel objects
*
* @param value
* @param contentProperty
* @param globalConfiguration
* @return
* @throws Exception
*/
CellData convertToExcelData(@NotNull T value, @Nullable ExcelContentProperty contentProperty) throws Exception;
CellData convertToExcelData(@NotNull T value, @Nullable ExcelContentProperty contentProperty,
@NotNull GlobalConfiguration globalConfiguration) throws Exception;
}

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

@ -5,6 +5,7 @@ import java.math.BigDecimal;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -25,7 +26,8 @@ public class BigDecimalBooleanConverter implements Converter<BigDecimal> {
}
@Override
public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) {
return BigDecimal.ONE;
}
@ -33,7 +35,8 @@ public class BigDecimalBooleanConverter implements Converter<BigDecimal> {
}
@Override
public CellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (BigDecimal.ONE.equals(value)) {
return new CellData(Boolean.TRUE);
}

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

@ -5,6 +5,7 @@ import java.math.BigDecimal;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -25,12 +26,14 @@ public class BigDecimalNumberConverter implements Converter<BigDecimal> {
}
@Override
public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return BigDecimal.valueOf(cellData.getDoubleValue());
}
@Override
public CellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value.doubleValue());
}
}

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

@ -5,6 +5,7 @@ import java.math.BigDecimal;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.NumberUtils;
@ -26,12 +27,14 @@ public class BigDecimalStringConverter implements Converter<BigDecimal> {
}
@Override
public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public BigDecimal convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new BigDecimal(cellData.getStringValue());
}
@Override
public CellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellData(value, contentProperty);
}
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.booleanconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -23,12 +24,14 @@ public class BooleanBooleanConverter implements Converter<Boolean> {
}
@Override
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getBooleanValue();
}
@Override
public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value);
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.booleanconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -26,7 +27,8 @@ public class BooleanNumberConverter implements Converter<Boolean> {
}
@Override
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (ONE.equals(cellData.getDoubleValue())) {
return Boolean.TRUE;
}
@ -34,7 +36,8 @@ public class BooleanNumberConverter implements Converter<Boolean> {
}
@Override
public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (value) {
return new CellData(ONE);
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.booleanconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -23,12 +24,14 @@ public class BooleanStringConverter implements Converter<Boolean> {
}
@Override
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return Boolean.valueOf(cellData.getStringValue());
}
@Override
public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Boolean value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value.toString());
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.byteconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -25,7 +26,8 @@ public class ByteBooleanConverter implements Converter<Byte> {
}
@Override
public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) {
return ONE;
}
@ -33,7 +35,8 @@ public class ByteBooleanConverter implements Converter<Byte> {
}
@Override
public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) {
return new CellData(Boolean.TRUE);
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.byteconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -23,12 +24,14 @@ public class ByteNumberConverter implements Converter<Byte> {
}
@Override
public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getDoubleValue().byteValue();
}
@Override
public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value.doubleValue());
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.byteconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.NumberUtils;
@ -24,12 +25,14 @@ public class ByteStringConverter implements Converter<Byte> {
}
@Override
public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return Byte.valueOf(cellData.getStringValue());
}
@Override
public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellData(value, contentProperty);
}

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

@ -7,6 +7,7 @@ import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -27,13 +28,10 @@ public class DateNumberConverter implements Converter<Date> {
}
@Override
public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
Boolean use1904windowing = Boolean.FALSE;
if (contentProperty != null && contentProperty.getUse1904windowing() != null) {
use1904windowing = contentProperty.getUse1904windowing();
}
return HSSFDateUtil.getJavaDate(cellData.getDoubleValue(), use1904windowing, null);
return HSSFDateUtil.getJavaDate(cellData.getDoubleValue(), globalConfiguration.getUse1904windowing(), null);
} else {
return HSSFDateUtil.getJavaDate(cellData.getDoubleValue(),
contentProperty.getDateTimeFormatProperty().getUse1904windowing(), null);
@ -41,7 +39,8 @@ public class DateNumberConverter implements Converter<Date> {
}
@Override
public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData((double)(value.getTime()));
}
}

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

@ -6,6 +6,7 @@ import java.util.Date;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.DateUtils;
@ -26,7 +27,8 @@ public class DateStringConverter implements Converter<Date> {
}
@Override
public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) throws ParseException {
public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws ParseException {
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
return DateUtils.parseDate(cellData.getStringValue(), null);
} else {
@ -36,7 +38,8 @@ public class DateStringConverter implements Converter<Date> {
}
@Override
public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
return new CellData(DateUtils.format(value, null));
} else {

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.doubleconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -25,7 +26,8 @@ public class DoubleBooleanConverter implements Converter<Double> {
}
@Override
public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) {
return ONE;
}
@ -33,7 +35,8 @@ public class DoubleBooleanConverter implements Converter<Double> {
}
@Override
public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) {
return new CellData(Boolean.TRUE);
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.doubleconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -23,12 +24,14 @@ public class DoubleNumberConverter implements Converter<Double> {
}
@Override
public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getDoubleValue();
}
@Override
public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value);
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.doubleconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.NumberUtils;
@ -24,12 +25,14 @@ public class DoubleStringConverter implements Converter<Double> {
}
@Override
public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Double convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return Double.valueOf(cellData.getStringValue());
}
@Override
public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellData(value, contentProperty);
}
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.floatconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -25,7 +26,8 @@ public class FloatBooleanConverter implements Converter<Float> {
}
@Override
public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) {
return ONE;
}
@ -33,7 +35,8 @@ public class FloatBooleanConverter implements Converter<Float> {
}
@Override
public CellData convertToExcelData(Float value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Float value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) {
return new CellData(Boolean.TRUE);
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.floatconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -23,12 +24,14 @@ public class FloatNumberConverter implements Converter<Float> {
}
@Override
public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getDoubleValue().floatValue();
}
@Override
public CellData convertToExcelData(Float value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Float value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value.doubleValue());
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.floatconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.NumberUtils;
@ -24,12 +25,14 @@ public class FloatStringConverter implements Converter<Float> {
}
@Override
public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return Float.valueOf(cellData.getStringValue());
}
@Override
public CellData convertToExcelData(Float value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Float value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellData(value, contentProperty);
}
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.integer;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -25,7 +26,8 @@ public class IntegerBooleanConverter implements Converter<Integer> {
}
@Override
public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) {
return ONE;
}
@ -33,7 +35,8 @@ public class IntegerBooleanConverter implements Converter<Integer> {
}
@Override
public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) {
return new CellData(Boolean.TRUE);
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.integer;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -23,12 +24,14 @@ public class IntegerNumberConverter implements Converter<Integer> {
}
@Override
public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getDoubleValue().intValue();
}
@Override
public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value.doubleValue());
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.integer;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.NumberUtils;
@ -24,12 +25,14 @@ public class IntegerStringConverter implements Converter<Integer> {
}
@Override
public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return Integer.valueOf(cellData.getStringValue());
}
@Override
public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellData(value, contentProperty);
}
}

7
src/main/java/com/alibaba/excel/converters/longconverter/LongBooleanConverter.java

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.longconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -25,7 +26,8 @@ public class LongBooleanConverter implements Converter<Long> {
}
@Override
public Long convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Long convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) {
return ONE;
}
@ -33,7 +35,8 @@ public class LongBooleanConverter implements Converter<Long> {
}
@Override
public CellData convertToExcelData(Long value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Long value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) {
return new CellData(Boolean.TRUE);
}

7
src/main/java/com/alibaba/excel/converters/longconverter/LongNumberConverter.java

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.longconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -23,12 +24,14 @@ public class LongNumberConverter implements Converter<Long> {
}
@Override
public Long convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Long convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getDoubleValue().longValue();
}
@Override
public CellData convertToExcelData(Long value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Long value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value.doubleValue());
}

7
src/main/java/com/alibaba/excel/converters/longconverter/LongStringConverter.java

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.longconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.NumberUtils;
@ -24,12 +25,14 @@ public class LongStringConverter implements Converter<Long> {
}
@Override
public Long convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Long convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return Long.valueOf(cellData.getStringValue());
}
@Override
public CellData convertToExcelData(Long value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Long value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellData(value, contentProperty);
}
}

7
src/main/java/com/alibaba/excel/converters/shortconverter/ShortBooleanConverter.java

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.shortconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -25,7 +26,8 @@ public class ShortBooleanConverter implements Converter<Short> {
}
@Override
public Short convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Short convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (cellData.getBooleanValue()) {
return ONE;
}
@ -33,7 +35,8 @@ public class ShortBooleanConverter implements Converter<Short> {
}
@Override
public CellData convertToExcelData(Short value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Short value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (ONE.equals(value)) {
return new CellData(Boolean.TRUE);
}

7
src/main/java/com/alibaba/excel/converters/shortconverter/ShortNumberConverter.java

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.shortconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -23,12 +24,14 @@ public class ShortNumberConverter implements Converter<Short> {
}
@Override
public Short convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Short convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getDoubleValue().shortValue();
}
@Override
public CellData convertToExcelData(Short value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Short value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value.doubleValue());
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.shortconverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.NumberUtils;
@ -24,12 +25,14 @@ public class ShortStringConverter implements Converter<Short> {
}
@Override
public Short convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public Short convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return Short.valueOf(cellData.getStringValue());
}
@Override
public CellData convertToExcelData(Short value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(Short value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return NumberUtils.formatToCellData(value, contentProperty);
}
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.string;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -23,12 +24,14 @@ public class StringBooleanConverter implements Converter<String> {
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getBooleanValue().toString();
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(Boolean.valueOf(value));
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.string;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -22,12 +23,14 @@ public class StringErrorConverter implements Converter<String> {
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getStringValue();
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(CellDataTypeEnum.ERROR, value);
}

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

@ -5,6 +5,7 @@ import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.DateUtils;
import com.alibaba.excel.util.NumberUtils;
@ -27,7 +28,8 @@ public class StringNumberConverter implements Converter<String> {
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
// If there are "DateTimeFormat", read as date
if (contentProperty != null && contentProperty.getDateTimeFormatProperty() != null) {
return DateUtils.format(
@ -40,7 +42,8 @@ public class StringNumberConverter implements Converter<String> {
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(Double.valueOf(value));
}
}

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

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.string;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
@ -22,12 +23,14 @@ public class StringStringConverter implements Converter<String> {
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) {
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return cellData.getStringValue();
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty) {
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return new CellData(value);
}

2
src/main/java/com/alibaba/excel/metadata/AbstractHolder.java

@ -10,7 +10,7 @@ import com.alibaba.excel.converters.Converter;
*
* @author zhuangjiaju
*/
public abstract class AbstractHolder implements Holder {
public abstract class AbstractHolder implements ConfigurationHolder {
/**
* Record whether it's new or from cache
*/

36
src/main/java/com/alibaba/excel/metadata/ConfigurationHolder.java

@ -0,0 +1,36 @@
package com.alibaba.excel.metadata;
import java.util.Map;
import com.alibaba.excel.converters.Converter;
/**
*
* Get the corresponding holder
*
* @author zhuangjiaju
**/
public interface ConfigurationHolder extends Holder {
/**
*
* Record whether it's new or from cache
*
* @return
*/
boolean isNew();
/**
* Some global variables
*
* @return
*/
GlobalConfiguration globalConfiguration();
/**
* What converter does the currently operated cell need to execute
*
* @return
*/
Map<String, Converter> converterMap();
}

24
src/main/java/com/alibaba/excel/metadata/Holder.java

@ -1,8 +1,5 @@
package com.alibaba.excel.metadata;
import java.util.Map;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.HolderEnum;
/**
@ -20,25 +17,4 @@ public interface Holder {
*/
HolderEnum holderType();
/**
*
* Record whether it's new or from cache
*
* @return
*/
boolean isNew();
/**
* Some global variables
*
* @return
*/
GlobalConfiguration globalConfiguration();
/**
* What converter does the currently operated cell need to execute
*
* @return
*/
Map<String, Converter> converterMap();
}

21
src/main/java/com/alibaba/excel/metadata/property/ExcelContentProperty.java

@ -2,6 +2,7 @@ package com.alibaba.excel.metadata.property;
import java.lang.reflect.Field;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.Head;
/**
@ -16,17 +17,13 @@ public class ExcelContentProperty {
* Excel head
*/
private Head head;
/**
* Custom defined converters
*/
private Converter converter;
private CellStyleProperty cellStyleProperty;
private DateTimeFormatProperty dateTimeFormatProperty;
private NumberFormatProperty numberFormatProperty;
/**
* true if date uses 1904 windowing, or false if using 1900 date windowing.
*
* default is false
*
* @return
*/
private Boolean use1904windowing;
public Field getField() {
return field;
@ -68,11 +65,11 @@ public class ExcelContentProperty {
this.numberFormatProperty = numberFormatProperty;
}
public Boolean getUse1904windowing() {
return use1904windowing;
public Converter getConverter() {
return converter;
}
public void setUse1904windowing(Boolean use1904windowing) {
this.use1904windowing = use1904windowing;
public void setConverter(Converter converter) {
this.converter = converter;
}
}

14
src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java

@ -14,7 +14,10 @@ import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.format.NumberFormat;
import com.alibaba.excel.converters.AutoConverter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.HeadKindEnum;
import com.alibaba.excel.exception.ExcelCommonException;
import com.alibaba.excel.exception.ExcelGenerateException;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.util.StringUtils;
@ -162,6 +165,17 @@ public class ExcelHeadProperty {
}
Head head = new Head(index, field.getName(), tmpHeadList, forceIndex);
ExcelContentProperty excelContentProperty = new ExcelContentProperty();
if (excelProperty != null && excelProperty.converter() != null) {
Class<? extends Converter> convertClazz = excelProperty.converter();
if (convertClazz != AutoConverter.class) {
try {
Converter converter = convertClazz.newInstance();
excelContentProperty.setConverter(converter);
} catch (Exception e) {
throw new ExcelCommonException("Can not instance custom converter:" + convertClazz.getName());
}
}
}
excelContentProperty.setHead(head);
excelContentProperty.setField(field);
excelContentProperty

1
src/main/java/com/alibaba/excel/parameter/GenerateParam.java

@ -7,6 +7,7 @@ import com.alibaba.excel.support.ExcelTypeEnum;
/**
* Created by jipengfei on 17/2/19.
*
* @author jipengfei
* @deprecated please use {@link com.alibaba.excel.write.builder.ExcelWriterBuilder} build ExcelWriter
*/
@Deprecated

20
src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java

@ -13,6 +13,7 @@ import com.alibaba.excel.enums.HeadKindEnum;
import com.alibaba.excel.event.AbstractIgnoreExceptionReadListener;
import com.alibaba.excel.exception.ExcelDataConvertException;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.read.metadata.holder.ReadHolder;
@ -40,7 +41,8 @@ public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener
private Object buildStringList(List<CellData> data, ReadHolder currentReadHolder) {
List<String> list = new ArrayList<String>();
for (CellData cellData : data) {
list.add((String)convertValue(cellData, String.class, null, currentReadHolder.converterMap()));
list.add((String)convertValue(cellData, String.class, null, currentReadHolder.converterMap(),
currentReadHolder.globalConfiguration()));
}
return list;
}
@ -54,8 +56,8 @@ public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener
throw new ExcelDataConvertException(
"Can not instance class: " + excelReadHeadProperty.getHeadClazz().getName(), e);
}
Map<String, Object> map = new HashMap<String, Object>();
Map<Integer, Head> headMap = excelReadHeadProperty.getHeadMap();
Map<String, Object> map = new HashMap<String, Object>(headMap.size() * 4 / 3 + 1);
Map<Integer, ExcelContentProperty> contentPropertyMap = excelReadHeadProperty.getContentPropertyMap();
for (Map.Entry<Integer, Head> entry : headMap.entrySet()) {
Integer index = entry.getKey();
@ -68,7 +70,7 @@ public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener
}
ExcelContentProperty excelContentProperty = contentPropertyMap.get(index);
Object value = convertValue(cellData, excelContentProperty.getField().getType(), excelContentProperty,
currentReadHolder.converterMap());
currentReadHolder.converterMap(), currentReadHolder.globalConfiguration());
if (value != null) {
map.put(excelContentProperty.getField().getName(), value);
}
@ -78,14 +80,20 @@ public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener
}
private Object convertValue(CellData cellData, Class clazz, ExcelContentProperty contentProperty,
Map<String, Converter> converterMap) {
Converter converter = converterMap.get(ConverterKeyBuild.buildKey(clazz, cellData.getType()));
Map<String, Converter> converterMap, GlobalConfiguration globalConfiguration) {
Converter converter = null;
if (contentProperty != null) {
converter = contentProperty.getConverter();
}
if (converter == null) {
converter = converterMap.get(ConverterKeyBuild.buildKey(clazz, cellData.getType()));
}
if (converter == null) {
throw new ExcelDataConvertException(
"Converter not found, convert " + cellData.getType() + " to " + clazz.getName());
}
try {
return converter.convertToJavaData(cellData, contentProperty);
return converter.convertToJavaData(cellData, contentProperty, globalConfiguration);
} catch (Exception e) {
throw new ExcelDataConvertException("Convert data " + cellData + " to " + clazz + " error ", e);
}

1
src/main/java/com/alibaba/excel/read/listener/ReadListenerRegistryCenter.java

@ -28,6 +28,7 @@ public interface ReadListenerRegistryCenter {
void notifyEndOneRow(AnalysisFinishEvent event, AnalysisContext analysisContext);
/**
* Notify after all analysed
*
* @param analysisContext
*/

11
src/main/java/com/alibaba/excel/read/listener/event/AnalysisFinishEvent.java

@ -1,5 +1,16 @@
package com.alibaba.excel.read.listener.event;
/**
*
* Event
*
* @author jipengfei
*/
public interface AnalysisFinishEvent {
/**
* Get result
*
* @return
*/
Object getAnalysisResult();
}

2
src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java

@ -189,7 +189,7 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH
"Converter not found, convert " + cellData.getType() + " to String");
}
try {
list.add((String)(converter.convertToJavaData(cellData, null)));
list.add((String)(converter.convertToJavaData(cellData, null, readHolder.globalConfiguration())));
} catch (Exception e) {
throw new ExcelDataConvertException("Convert data " + cellData + " to String error ", e);
}

4
src/main/java/com/alibaba/excel/read/metadata/holder/ReadHolder.java

@ -2,7 +2,7 @@ package com.alibaba.excel.read.metadata.holder;
import java.util.List;
import com.alibaba.excel.metadata.Holder;
import com.alibaba.excel.metadata.ConfigurationHolder;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.read.metadata.property.ExcelReadHeadProperty;
@ -12,7 +12,7 @@ import com.alibaba.excel.read.metadata.property.ExcelReadHeadProperty;
*
* @author zhuangjiaju
**/
public interface ReadHolder extends Holder {
public interface ReadHolder extends ConfigurationHolder {
/**
* What handler does the currently operated cell need to execute
*

9
src/main/java/com/alibaba/excel/read/metadata/holder/ReadRowHolder.java

@ -1,13 +1,15 @@
package com.alibaba.excel.read.metadata.holder;
import com.alibaba.excel.enums.HolderEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.Holder;
/**
* sheet holder
*
* @author zhuangjiaju
*/
public class ReadRowHolder {
public class ReadRowHolder implements Holder {
/**
* Returns row index of a row in the sheet that contains this cell.Start form 0.
*/
@ -50,4 +52,9 @@ public class ReadRowHolder {
public void setRowIndex(int rowIndex) {
this.rowIndex = rowIndex;
}
@Override
public HolderEnum holderType() {
return HolderEnum.ROW;
}
}

13
src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java

@ -76,7 +76,6 @@ public class ExcelBuilderImpl implements ExcelBuilder {
@Override
public void addContent(List data, WriteSheet writeSheet, WriteTable writeTable) {
try {
context.currentSheet(writeSheet);
context.currentTable(writeTable);
doAddContent(data);
@ -254,15 +253,21 @@ public class ExcelBuilderImpl implements ExcelBuilder {
if (value == null) {
return;
}
Converter converter = currentWriteHolder.converterMap().get(ConverterKeyBuild.buildKey(clazz));
if (value instanceof String && currentWriteHolder.globalConfiguration().getAutoTrim()) {
value = ((String)value).trim();
}
Converter converter = excelContentProperty.getConverter();
if (converter == null) {
converter = currentWriteHolder.converterMap().get(ConverterKeyBuild.buildKey(clazz));
}
if (converter == null) {
throw new ExcelDataConvertException(
"Can not find 'Converter' support class " + clazz.getSimpleName() + ".");
}
CellData cellData;
try {
cellData = converter.convertToExcelData(value, excelContentProperty);
cellData =
converter.convertToExcelData(value, excelContentProperty, currentWriteHolder.globalConfiguration());
} catch (Exception e) {
throw new ExcelDataConvertException("Convert data:" + value + " error,at row:" + cell.getRow().getRowNum(),
e);

4
src/main/java/com/alibaba/excel/write/metadata/holder/WriteHolder.java

@ -3,7 +3,7 @@ package com.alibaba.excel.write.metadata.holder;
import java.util.List;
import java.util.Map;
import com.alibaba.excel.metadata.Holder;
import com.alibaba.excel.metadata.ConfigurationHolder;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.property.ExcelWriteHeadProperty;
@ -13,7 +13,7 @@ import com.alibaba.excel.write.property.ExcelWriteHeadProperty;
*
* @author zhuangjiaju
**/
public interface WriteHolder extends Holder {
public interface WriteHolder extends ConfigurationHolder {
/**
* What 'ExcelWriteHeadProperty' does the currently operated cell need to execute
*/

Loading…
Cancel
Save