diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/poi/excel/converter/DateConverter.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/poi/excel/converter/DateConverter.java new file mode 100644 index 0000000000..6fae39280d --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/poi/excel/converter/DateConverter.java @@ -0,0 +1,47 @@ +package com.epmet.commons.tools.utils.poi.excel.converter; + +/** + * desc: + * + * @author: LiuJanJun + * @date: 2022/8/26 4:59 下午 + * @version: 1.0 + */ + +import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.WriteCellData; +import com.alibaba.excel.metadata.property.ExcelContentProperty; + +import java.text.SimpleDateFormat; +import java.util.Date; + +package com.lxj.common.convert; + +/** + * @Author: liujianjun + * @Date: 2022/7/19 + * @Description: yyyy-MM-dd easyExcel 日期转换 + */ +public class DateConverter implements Converter { + + private static final String PATTERN_YYYY_MM_DD = "yyyy-MM-dd"; + + @Override + public Class supportJavaTypeKey() { + return Converter.super.supportJavaTypeKey(); + } + + @Override + public CellDataTypeEnum supportExcelTypeKey() { + return Converter.super.supportExcelTypeKey(); + } + + @Override + public WriteCellData convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { + SimpleDateFormat sdf = new SimpleDateFormat(PATTERN_YYYY_MM_DD); + String dateValue = sdf.format(value); + return new WriteCellData<>(dateValue); + } +}