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

相关推荐
用户2986985301419 小时前
React 前端实现 Excel 与 CSV 互转:基于 WebAssembly 的浏览器端方案
javascript·react.js·excel
仓库日记2 天前
Excel进销存何时该换?用3项检查判断是否需要软件
经验分享·excel·进销存·开单软件
用户0332126663672 天前
如何使用 Python 将 JSON 转换为 Excel
python·excel
2601_967980113 天前
Python自动化办公:模块、库与样式调整教程
python·excel·自动化办公·openpyxl·样式调整
用户0332126663673 天前
使用 Python 轻松加密或解密 Excel 文档
python·excel
总裁余(余登武)4 天前
【python项目】:1操作EXCEl自动化开发
python·自动化·excel
ailitsoft6 天前
库存管理系统如何记录跨门店调拨后的收货差异?
excel·零售·软件需求
百事牛科技8 天前
Excel的三种密码:防看、防存、防乱改,各管各的
windows·excel
用户298698530148 天前
React 前端将 Excel 工作表导出为图片的技术实践
javascript·react.js·excel
用户0332126663679 天前
使用 Python 在 Excel 文档中添加水印
python·excel