com.swak.excel.converter.LocalDataTimeConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swak-excel-boot-starter Show documentation
Show all versions of swak-excel-boot-starter Show documentation
swak component of excel spring boot starter
The newest version!
package com.swak.excel.converter;
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;
import java.util.Date;
public class LocalDataTimeConverter implements Converter {
private static final String PARSE_PATTERN = "yyyy-MM-dd HH:mm:ss";
@Override
public Class> supportJavaTypeKey() {
return Date.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public Date convertToJavaData(ReadCellData> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws Exception {
return DateUtils.parseDate(cellData.getStringValue());
}
@Override
public WriteCellData> convertToExcelData(Date value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws Exception {
return new WriteCellData<>(DateUtils.format(value, PARSE_PATTERN));
}
}