EasyExcel 在处理 Excel 文件时,需要占用一定的内存。如果导出的数据量过大,可能导致内存占用过高,从而引发 CPU 过高的问题。并发访问导出接口也会导致性能问题,所以尽量在数据量比较大的导出接口添加锁控制。
以下是虚化业务后的代码,记录一下遇到的问题解决方案
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
public void exportBigExcelist(HttpServletResponse response, RequestForm requestForm) throws ParseException, IOException { ExportParams params = new ExportParams("标题", "sheet名称");
Workbook workbook = ExcelExportUtil.exportBigExcel(params, ExcelDto.class, new IExcelExportServer() { @SneakyThrows @Override public List<Object> selectListForExcelExport(Object queryParams, int page) { RequestForm tempForm = (RequestForm) queryParams; tempForm.setPage(page); tempForm.setPageSize(10000); List<ExcelDto> list = service.selectlist(tempForm); List<Object> objects = new ArrayList<>(list); if (list.size() == 0) { return null; } return objects; } }, requestForm);
response.setHeader("content-Type", "application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("filename.xls", "UTF-8")); workbook.write(response.getOutputStream()); }
|