我是靠谱客的博主 迷人大叔,这篇文章主要介绍java导出excel表格 使用alibaba easyexcel,现在分享给大家,希望可以做个参考。

开发中有好多时候需要导出表格,以往通常使用poi 这些jar进行倒入导出。
最近发现 阿里巴巴的一个 easyexcel 导出非常方便 记录下
项目地址

先添加依赖

复制代码
1
2
3
4
5
6
7
<dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>1.1.2-beta5</version> </dependency>

controller 层

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public void downloadPointsList(@RequestParam(defaultValue = "0",required = false) int type , @RequestParam(defaultValue = "",required = false) String begintime, @RequestParam(defaultValue = "",required = false) String endtime , HttpServletResponse response) throws IOException { List<MemberPoints> downLoads = memberPointsService.downloadBytime(type,begintime,endtime); OutputStream out = response.getOutputStream(); ExcelWriter writer =new ExcelWriter(out, ExcelTypeEnum.XLSX); Sheet sheet1 =new Sheet(1, 0, MemberPoints.class); sheet1.setSheetName("会员积分"); response.setCharacterEncoding("utf-8"); response.setContentType("application/vnd.ms-excel;charset=utf-8"); response.setHeader("Content-Disposition", "attachment;filename=" +new String(( "会员积分数据.xlsx").getBytes(), "ISO8859-1")); writer.write(downLoads, sheet1); writer.finish(); out.flush(); out.close(); }

这里阿里是根据 实体类的注解 去生成表头对应的

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class MemberPoints extends BaseRowModel { /** * ID */ @ExcelProperty(value = "ID",index = 0) private Long id; /** * 会员ID */ @ExcelProperty(value = "会员ID",index = 1) private Long memberId; /** * 类型 1获得 2 支出 */ @ExcelProperty(value = "类型",index =5) private Integer type; }

最后

以上就是迷人大叔最近收集整理的关于java导出excel表格 使用alibaba easyexcel的全部内容,更多相关java导出excel表格内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(97)

评论列表共有 0 条评论

立即
投稿
返回
顶部