mirror of https://github.com/alibaba/easyexcel
Jiaju Zhuang
3 years ago
17 changed files with 335 additions and 4 deletions
@ -0,0 +1,47 @@
|
||||
package com.alibaba.excel.converters.biginteger; |
||||
|
||||
import java.math.BigInteger; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.metadata.GlobalConfiguration; |
||||
import com.alibaba.excel.metadata.data.ReadCellData; |
||||
import com.alibaba.excel.metadata.data.WriteCellData; |
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
||||
|
||||
/** |
||||
* BigInteger and boolean converter |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public class BigIntegerBooleanConverter implements Converter<BigInteger> { |
||||
|
||||
@Override |
||||
public Class<BigInteger> supportJavaTypeKey() { |
||||
return BigInteger.class; |
||||
} |
||||
|
||||
@Override |
||||
public CellDataTypeEnum supportExcelTypeKey() { |
||||
return CellDataTypeEnum.BOOLEAN; |
||||
} |
||||
|
||||
@Override |
||||
public BigInteger convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, |
||||
GlobalConfiguration globalConfiguration) { |
||||
if (cellData.getBooleanValue()) { |
||||
return BigInteger.ONE; |
||||
} |
||||
return BigInteger.ZERO; |
||||
} |
||||
|
||||
@Override |
||||
public WriteCellData<?> convertToExcelData(BigInteger value, ExcelContentProperty contentProperty, |
||||
GlobalConfiguration globalConfiguration) { |
||||
if (BigInteger.ONE.equals(value)) { |
||||
return new WriteCellData<>(Boolean.TRUE); |
||||
} |
||||
return new WriteCellData<>(Boolean.FALSE); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,41 @@
|
||||
package com.alibaba.excel.converters.biginteger; |
||||
|
||||
import java.math.BigInteger; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.metadata.GlobalConfiguration; |
||||
import com.alibaba.excel.metadata.data.ReadCellData; |
||||
import com.alibaba.excel.metadata.data.WriteCellData; |
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
||||
import com.alibaba.excel.util.NumberUtils; |
||||
|
||||
/** |
||||
* BigInteger and number converter |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public class BigIntegerNumberConverter implements Converter<BigInteger> { |
||||
|
||||
@Override |
||||
public Class<BigInteger> supportJavaTypeKey() { |
||||
return BigInteger.class; |
||||
} |
||||
|
||||
@Override |
||||
public CellDataTypeEnum supportExcelTypeKey() { |
||||
return CellDataTypeEnum.NUMBER; |
||||
} |
||||
|
||||
@Override |
||||
public BigInteger convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, |
||||
GlobalConfiguration globalConfiguration) { |
||||
return cellData.getNumberValue().toBigInteger(); |
||||
} |
||||
|
||||
@Override |
||||
public WriteCellData<?> convertToExcelData(BigInteger value, ExcelContentProperty contentProperty, |
||||
GlobalConfiguration globalConfiguration) { |
||||
return NumberUtils.formatToCellData(value, contentProperty); |
||||
} |
||||
} |
@ -0,0 +1,55 @@
|
||||
package com.alibaba.excel.converters.localdatetime; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.time.LocalDateTime; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.metadata.GlobalConfiguration; |
||||
import com.alibaba.excel.metadata.data.ReadCellData; |
||||
import com.alibaba.excel.metadata.data.WriteCellData; |
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
||||
|
||||
import org.apache.poi.ss.usermodel.DateUtil; |
||||
|
||||
/** |
||||
* LocalDateTime and number converter |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public class LocalDateNumberConverter implements Converter<LocalDateTime> { |
||||
|
||||
@Override |
||||
public Class<?> supportJavaTypeKey() { |
||||
return LocalDateTime.class; |
||||
} |
||||
|
||||
@Override |
||||
public CellDataTypeEnum supportExcelTypeKey() { |
||||
return CellDataTypeEnum.NUMBER; |
||||
} |
||||
|
||||
@Override |
||||
public LocalDateTime convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, |
||||
GlobalConfiguration globalConfiguration) { |
||||
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { |
||||
return DateUtil.getLocalDateTime(cellData.getNumberValue().doubleValue(), |
||||
globalConfiguration.getUse1904windowing()); |
||||
} else { |
||||
return DateUtil.getLocalDateTime(cellData.getNumberValue().doubleValue(), |
||||
contentProperty.getDateTimeFormatProperty().getUse1904windowing()); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public WriteCellData<?> convertToExcelData(LocalDateTime value, ExcelContentProperty contentProperty, |
||||
GlobalConfiguration globalConfiguration) { |
||||
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { |
||||
return new WriteCellData<>( |
||||
BigDecimal.valueOf(DateUtil.getExcelDate(value, globalConfiguration.getUse1904windowing()))); |
||||
} else { |
||||
return new WriteCellData<>(BigDecimal.valueOf( |
||||
DateUtil.getExcelDate(value, contentProperty.getDateTimeFormatProperty().getUse1904windowing()))); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.alibaba.excel.converters.localdatetime; |
||||
|
||||
import java.time.LocalDateTime; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.metadata.GlobalConfiguration; |
||||
import com.alibaba.excel.metadata.data.WriteCellData; |
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
||||
import com.alibaba.excel.util.DateUtils; |
||||
import com.alibaba.excel.util.WorkBookUtil; |
||||
|
||||
/** |
||||
* Date and date converter |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public class LocalDateTimeDateConverter implements Converter<LocalDateTime> { |
||||
@Override |
||||
public Class<LocalDateTime> supportJavaTypeKey() { |
||||
return LocalDateTime.class; |
||||
} |
||||
|
||||
@Override |
||||
public WriteCellData<?> convertToExcelData(LocalDateTime value, ExcelContentProperty contentProperty, |
||||
GlobalConfiguration globalConfiguration) throws Exception { |
||||
WriteCellData<?> cellData = new WriteCellData<>(value); |
||||
String format = null; |
||||
if (contentProperty != null && contentProperty.getDateTimeFormatProperty() != null) { |
||||
format = contentProperty.getDateTimeFormatProperty().getFormat(); |
||||
} |
||||
WorkBookUtil.fillDataFormat(cellData, format, DateUtils.defaultDateFormat); |
||||
return cellData; |
||||
} |
||||
} |
@ -0,0 +1,52 @@
|
||||
package com.alibaba.excel.converters.localdatetime; |
||||
|
||||
import java.text.ParseException; |
||||
import java.time.LocalDateTime; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.metadata.GlobalConfiguration; |
||||
import com.alibaba.excel.metadata.data.ReadCellData; |
||||
import com.alibaba.excel.metadata.data.WriteCellData; |
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
||||
import com.alibaba.excel.util.DateUtils; |
||||
|
||||
/** |
||||
* LocalDateTime and string converter |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public class LocalDateTimeStringConverter implements Converter<LocalDateTime> { |
||||
@Override |
||||
public Class<?> supportJavaTypeKey() { |
||||
return LocalDateTime.class; |
||||
} |
||||
|
||||
@Override |
||||
public CellDataTypeEnum supportExcelTypeKey() { |
||||
return CellDataTypeEnum.STRING; |
||||
} |
||||
|
||||
@Override |
||||
public LocalDateTime convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, |
||||
GlobalConfiguration globalConfiguration) throws ParseException { |
||||
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { |
||||
return DateUtils.parseLocalDateTime(cellData.getStringValue(), null, globalConfiguration.getLocale()); |
||||
} else { |
||||
return DateUtils.parseLocalDateTime(cellData.getStringValue(), |
||||
contentProperty.getDateTimeFormatProperty().getFormat(), globalConfiguration.getLocale()); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public WriteCellData<?> convertToExcelData(LocalDateTime value, ExcelContentProperty contentProperty, |
||||
GlobalConfiguration globalConfiguration) { |
||||
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { |
||||
return new WriteCellData<>(DateUtils.format(value, null, globalConfiguration.getLocale())); |
||||
} else { |
||||
return new WriteCellData<>( |
||||
DateUtils.format(value, contentProperty.getDateTimeFormatProperty().getFormat(), |
||||
globalConfiguration.getLocale())); |
||||
} |
||||
} |
||||
} |
Binary file not shown.
Binary file not shown.
|
Loading…
Reference in new issue