ExcelExportUtil.exportExcel()导出文件出现乱码
时间: 2023-10-08 14:06:32 浏览: 217
解决tableExport导出到excel中文乱码
出现乱码的原因可能是导出的Excel文件编码格式和浏览器的编码格式不一致。可以尝试在设置response的header时,指定编码格式为UTF-8,如下所示:
```
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=\"" + exportReq.getFileName() + ".xlsx\"");
```
另外,ExcelExportUtil.exportExcel()方法有多个重载,可以尝试使用重载方法,设置导出Excel文件的编码格式,例如:
```
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(exportReq.getFileName(), "sheet1", ExcelType.XSSF), TagDetail.class, exportReq.getTagDetails());
workbook.setSheetName(0, "sheet1");
workbook.setSheetName(1, "sheet2");
workbook.setSheetName(2, "sheet3");
workbook.setSheetName(3, "sheet4");
workbook.setSheetName(4, "sheet5");
workbook.setSheetName(5, "sheet6");
workbook.setSheetName(6, "sheet7");
workbook.setSheetName(7, "sheet8");
workbook.setSheetName(8, "sheet9");
workbook.setSheetName(9, "sheet10");
workbook.setSheetName(10, "sheet11");
workbook.setSheetName(11, "sheet12");
workbook.setSheetName(12, "sheet13");
workbook.setSheetName(13, "sheet14");
workbook.setSheetName(14, "sheet15");
workbook.setSheetName(15, "sheet16");
workbook.setSheetName(16, "sheet17");
workbook.setSheetName(17, "sheet18");
workbook.setSheetName(18, "sheet19");
workbook.setSheetName(19, "sheet20");
workbook.setCharset("UTF-8");
```
需要注意的是,设置编码格式需要在导出Excel文件之前进行。
阅读全文