数据文件导出

一、 Excel文件导出

1.1 文件导出报错:java.lang.IllegalStateException: The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook

解决方式: .xls 改为 .xlsx 同时:Workbook 使用 XSSF

java 复制代码
 long start = System.currentTimeMillis();
        ExportParams exportParams = new ExportParams(fileName, sheetName);
        exportParams.setStyle(ExcelGlobalColorStyler.class);
        exportParams.setType(ExcelType.XSSF);
        Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, dataSet);
        log.info("导出耗时:{}ms", System.currentTimeMillis() - start);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment;filename=" +
//                java.net.URLEncoder.encode(fileName+".xls", "UTF-8"));
                java.net.URLEncoder.encode(fileName+".xlsx", "UTF-8"));
        OutputStream outputStream = response.getOutputStream();
        workbook.write(outputStream);
        outputStream.flush();
        outputStream.close();
        workbook.close();