1.EasyExcel 介绍
EasyExcel是一个基于Java的简单、省内存的读写Excel的开源项目。在尽可能节约内存的情况下支持读写百M的Excel
参考地址:
https://www.yuque.com/easyexcel/doc/easyexcel
2 开发步骤
2.1 添加依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.7</version>
</dependency>
2.2 controller
@RequestMapping("toExcel")
public ResponseEntity<byte[]> toExcel(GoodsVO goodsVO, @RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "3")Integer pageSize, Model model) throws IOException {
PageInfo<Goods> info = goodsService.list(goodsVO, pageNum, pageSize);
String filename=UUID.randomUUID().toString()+".xlsx"; //excel 文件名称
File file=new File("d:/pic/",filename);//文件对象
EasyExcel.write(file,Goods.class).sheet("商品报表").doWrite(info.getList());//写入excel文件
HttpHeaders headers = new HttpHeaders();//http头信息
headers.setContentDispositionFormData("attachment", filename); //以附件进行下载
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
}
本文暂时没有评论,来添加一个吧(●'◡'●)