【文件下载】Easyexcel百万数据量以上数据导出
一、引入依赖
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
二、实现代码(泛型和数据集合切换成你自己的)
@GetMapping("bondBaseAll")
public void bondBaseAll(HttpServletResponse response) throws IOException {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment; filename=全信用债.xlsx");
List<BondBaseAll> list = bondBaseAllService.list();//把这里换成你自己的集合数据,泛型全部改为你的实体类
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();
List<List<BondBaseAll>> lists = Lists.partition(list, 500000);//500000表示每一个sheet页有500000数据
for (int i = 0; i < lists.size(); i++) {
WriteSheet mainSheet = EasyExcel.writerSheet(i, "sheet" + (i + 1)).head(BondBaseAll.class).build();
//向sheet写入数据 传入空list这样只导出表头
excelWriter.write(lists.get(i), mainSheet);
}
excelWriter.finish();
response.flushBuffer();
}
总结:由此可以实现百万数量量以上的文件导出
