2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > java导出excel表格 使用alibaba easyexcel

java导出excel表格 使用alibaba easyexcel

时间:2023-12-31 15:26:33

相关推荐

java导出excel表格 使用alibaba easyexcel

开发中有好多时候需要导出表格,以往通常使用poi 这些jar进行倒入导出。

最近发现 阿里巴巴的一个 easyexcel 导出非常方便 记录下

项目地址

先添加依赖

<dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>1.1.2-beta5</version></dependency>

controller 层

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

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

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。