百万级别的大批量excel导出
1 导入pom
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.6.1</version>
</dependency>
2 主逻辑
@GetMapping("/test1")
public void test2(HttpServletResponse response) throws IOException {
ServletOutputStream outputStream = response.getOutputStream();
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition","attachment;filename=test.xlsx");
ExcelWriter bigWriter = ExcelUtil.getBigWriter();
List<User> list1 = new ArrayList<>();
for (int i = 0; i < 1000000 ; i++) {
User user = new User(String.valueOf(i+1),String.valueOf(i));
list1.add(user);
}
bigWriter.write(list1);
bigWriter.flush(outputStream);
bigWriter.close();
return;
}