package com.qianwen.core.excel.extend.converters;
|
|
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 java.text.ParseException;
|
import java.time.LocalDate;
|
import java.time.format.DateTimeFormatter;
|
|
/* loaded from: blade-starter-excel-9.3.0.0-SNAPSHOT.jar:org/springblade/core/excel/extend/converters/LocalDateStringConverter.class */
|
public enum LocalDateStringConverter implements Converter<LocalDate> {
|
INSTANCE;
|
|
public Class supportJavaTypeKey() {
|
return LocalDate.class;
|
}
|
|
public CellDataTypeEnum supportExcelTypeKey() {
|
return CellDataTypeEnum.STRING;
|
}
|
|
public LocalDate convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException {
|
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null)
|
return LocalDate.parse(cellData.getStringValue());
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(contentProperty.getDateTimeFormatProperty().getFormat());
|
return LocalDate.parse(cellData.getStringValue(), formatter);
|
}
|
|
public CellData<String> convertToExcelData(LocalDate value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
DateTimeFormatter formatter;
|
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
|
formatter = DateTimeFormatter.ISO_LOCAL_DATE;
|
} else {
|
formatter = DateTimeFormatter.ofPattern(contentProperty.getDateTimeFormatProperty().getFormat());
|
}
|
return new CellData<>(value.format(formatter));
|
}
|
}
|