1.EasyExcel 介绍
EasyExcel是一个基于Java的简单、省内存的读写Excel的开源项目。在尽可能节约内存的情况下支持读写百M的Excel
参考地址:
https://www.yuque.com/easyexcel/doc/easyexcel
2 开发步骤
2.1 添加依赖
com.alibaba
easyexcel
2.1.7
2.2 controller
@RequestMapping("toExcel")
public ResponseEntity toExcel(GoodsVO goodsVO, @RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "3")Integer pageSize, Model model) throws IOException {
PageInfo 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(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
}
2.3 实体类

2.3 页面导出
2.4excel内容效果