一、简介
在上篇文章《Springboot导出大数据量excel(二)-分页查询数据List<Map>》说道excel的最大支持数据行数1048576(2的20次方)。本文内容主要就是解决这个问题。
二、效果展示
导出200行数据,每个文件存储10万行数据。
三、源码
controller
@RequestMapping(value = "export5", method = RequestMethod.GET)
@ApiOperation(value = "导出大量数据(zip)", notes = "csv")
@ApiImplicitParams({})
public void export5(HttpServletResponse response, HttpServletRequest request) throws Exception {
Date start = new Date();
Map params = new HashMap<>();
params.put("pageSize", 10000);
String fileName = "csv_" + System.currentTimeMillis();
ExcelUtil.exportCsvZip(params, response, fileName, 100000, (param, page) -> {
param.put("pageNum", page);
//查询数据
List
ExcelUtil.exportCsvZip
public static void exportCsvZip(Map queryParams, HttpServletResponse response, String fileName, int fileRowCount, MyExcelExportServer server) throws IOException {
//使用临时文件
List fileList = new ArrayList<>();
//设置response参数
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".zip", "UTF-8"));
response.setContentType("application/x-zip-compressed");
File file = null;
FileWriter writer = null;
CSVPrinter printer = null;
try (ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream());) {
List
源码地址
POI大数据量导出