首页 > 其他分享 >EasyExcel导出Date类型格式处理

EasyExcel导出Date类型格式处理

时间:2022-10-30 09:11:28浏览次数:73  
标签:Converter 导出 EasyExcel excel alibaba Date import com

EasyExcel导出Date类型格式处理

​ 如果在导出的excel中有date时间类型的字段,直接导出会报错org.apache.poi.ss.usermodel.Cell.setCellValue(Ljava/time/LocalDateTime;),因此需要做类型转换,需要实现Converter<Date>接口;

package com.pms.rcm.reports.manager;


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;

/**
 * @author : sean
 * @date Date : 2022-10-29 23:21
 * @Description:
 */

public class DateConverter implements Converter<Date> {

    private static final String PATTERN_YYYY_MM_DD = "yyyy-MM-dd hh:mm:hh";

    @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);
    }
}

如果excel中不需要导出date时间类型的字段,那么可以在字段上使用注解@ExcelIgnore 或在实体类上使用注解@ExcelIgnoreUnannotated

参考连接:https://blog.csdn.net/weixin_48437239/article/details/125875164

标签:Converter,导出,EasyExcel,excel,alibaba,Date,import,com
From: https://www.cnblogs.com/seanRay/p/16840493.html

相关文章

  • Oracle 增删改(INSERT、DELETE、UPDATE)语句
    Ø  简介本文介绍 Oracle 中的增删改语句,即 INSERT、DELETE、UPDATE 语句的使用。是时候展现真正的技术了,快上车:插入数据(INSERT)修改数据(UPDATE)删除数据(DEL......
  • antd的update组件自定义上传样式及列表样式
    项目需求按UI设计上传的样式需要把showUploadList={false},自己写上传列表//本次上传的文件const[fileList,setFileList]=useState([]);//初始化时存储之前上传......
  • TypeScript日期工具: date-fns日期工具的使用方法
    1、引入$npminstall--savedate-fns2、使用import{isToday,isYesterday,isTomorrow,format,addYears,addMonths,addDays,addHours,add......
  • String类型时间与Date时间转换
    1.String类型的时间转为DateTimepublicstaticDatetransferString2Date(Strings){Datedate=newDate();try{date=newSimpleDateFormat("......
  • delphi TMS FlexCel 导出页面设置
    TMSFlexCel导出页面设置属性和方法TFlexCelHtmlExport.HidePrintObjectspropertyHidePrintObjects:SetofTHidePrintObjects选择哪些类型的对象不应该导出。导......
  • docker 中 apt-get update 失败解决方案
    1.更换apt的镜像源1.1进入目录cd/etc/apt1.2备份源文件cp/etc/apt/sources.list/etc/apt/sources.list.bak1.3更改镜像源cat<<EOF>/etc/apt/sources.listde......
  • JavaScript--Date
    一、Date的概述在JavaScript中,Date类型是用来保存日期的,它能精确到1970年1月1日之前或之后的285616年。二、Date的声明使用new关键字声明要创建一个日期对象,使用new操......
  • DateTimeHelper
    usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceZB.QueueSys.Common{publicclassDateTimeHelper{......
  • 导出报错cannot be resolved to absolute file path because it does not reside in t
    SpringBoot项目打包部署,读取jar里面的文件报错500,异常日志关键提示cannotberesolvedtoabsolutefilepathbecauseitdoesnotresideinthefilesystem报错定位......
  • mysql update 带条件的语句执行错误
    需求:想着更新id最大的一条数据: 原来的sql:   updatework_plane_log_detailsSET`off_working_time`='2021-03-0911:16:23'WHEREidin(selectidfromwork_pl......