easyExcel注解导出

使用注解导出 (数据量大时使用)

参考官方文档

https://easyexcel.opensource.alibaba.com/docs/current/quickstart/write

1.导入依赖

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.3.2</version>
</dependency>

2.实体类

类上加这个注解,否则属性不需要导出的也给导出来了

@ExcelIgnoreUnannotated

属性加入 @ExcelProperty注解

@ExcelProperty
private String unitNature;

image

3.编码 web中导出

private void download(List<TaxProblemCountDetailsResult> taxProblemCountNew, HttpServletResponse response) throws IOException {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
String fileName = URLEncoder.encode("纳税_具体问题统计", "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel.write(response.getOutputStream(), TaxProblemCountDetailsResult.class).sheet("纳税_具体问题统计").doWrite(taxProblemCountNew);
}
posted @   进击的乌拉  阅读(107)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示