easyexcel和poi同时存在版本问题,使用easyexcel导出excel设置日期格式

这两天在使用easyexcel导出excel的时候日期格式全都是字符串导致导出的excel列无法筛选

后来调整了一下终于弄好了,看一下最终效果

这里涉及到easyexcel和poi版本冲突的问题,一直没搞定,最后狠下心来把所有的都升级到了最新版,然后把程序里的报错都处理了一遍,神奇的是最新版的没出问题,可以导出日期格式,参考了很多博客,记录一下。

最终要调整的地方有三个,一个是poi的版本,一个是easyexcel的版本,另一个是commons-io的版本

xml 复制代码
<commons-io.version>2.18.0</commons-io.version>
<poi.version>5.4.0</poi.version>
<easy-excel.version>4.0.3</easy-excel.version>

<dependency>
	 <groupId>commons-io</groupId>
	 <artifactId>commons-io</artifactId>
	 <version>${commons-io.version}</version>
</dependency>
<dependency>
     <groupId>org.apache.poi</groupId>
     <artifactId>poi</artifactId>
     <version>${poi.version}</version>
 </dependency>
 <dependency>
     <groupId>org.apache.poi</groupId>
     <artifactId>poi-ooxml</artifactId>
     <version>${poi.version}</version>
 </dependency>
 <dependency>
     <groupId>com.alibaba</groupId>
     <artifactId>easyexcel</artifactId>
     <version>${easy-excel.version}</version>
 </dependency>

注意事项

  1. poi的版本对commons-io的版本有要求

https://blog.csdn.net/weixin_48524970/article/details/134379243
https://poi.apache.org/changes.html#5.4.0

  1. 日期格式使用 @ContentStyle(dataFormat = 14)

https://blog.csdn.net/tanghuan0827/article/details/126180146

  1. 日期格式不要进行Converter转换,否则都是字符串

下面是我的实体类的字段

java 复制代码
   @ContentStyle(dataFormat = 14)
   @ExcelProperty(value = {"购入日期"}, index = 9)
   private Date buyDate;
   
   @ContentStyle(dataFormat = 14)
   @ExcelProperty(value = {"报废日期"}, index = 10)
   private LocalDate scrapDate;
   

这种Date和LocalDate导出的数据都是日期格式,关键的设置是@ContentStyle(dataFormat = 14)

参考文献

https://blog.csdn.net/tanghuan0827/article/details/126180146
https://blog.csdn.net/weixin_48524970/article/details/134379243
https://poi.apache.org/changes.html#5.4.0

相关推荐
骆驼爱记录1 小时前
Excel数据源到Word成绩单自动生成
自动化·word·excel·wps·新人首发
开开心心_Every3 小时前
手机PDF处理工具:支持格式转换与批注
游戏·微信·智能手机·pdf·逻辑回归·excel·语音识别
岁月@可回首20 小时前
两个excel中寻找相同关键词下的内容,将一个需要的内容复制到另一个excel
excel
云纳星辰怀自在21 小时前
基于VBA调用API在Excel中自动生成音标和翻译
excel·单词自动生成音标·excel自动翻译
daols881 天前
vue2 表格如何使用 vxe-table 带列头复制单元格内容同步到 excel 中
vue.js·excel·vxe-table
JSON_L1 天前
Fastadmin Excel 导入实现
php·excel·fastadmin
E_ICEBLUE2 天前
Excel vs CSV:在系统数据处理中该如何选择?
java·excel·csv·格式转换
weixin_318088112 天前
Power query代替PowerBI加载数据到excel
excel·powerbi·power query
weixin_419349792 天前
excel批量把自身加上链接,这一列本身就是网址
excel
meng半颗糖2 天前
vue3+typeScript 在线预览 excel,word,pdf
typescript·word·excel