5
触发Bug的代码
public static void exportExcel(String fileName, List data, Class clazz, HttpServletResponse response) {
try {
// 初始化样式
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
WriteFont headWriteFont = new WriteFont();
headWriteFont.setFontHeightInPoints((short) 11);
headWriteCellStyle.setWriteFont(headWriteFont);
HorizontalCellStyleStrategy handler = new HorizontalCellStyleStrategy(headWriteCellStyle, new WriteCellStyle());
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding(StandardCharsets.UTF_8.toString());
// 处理中文乱码
String encode = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());
response.setHeader("Content-disposition", "attachment;filename=" + encode + ExcelTypeEnum.XLSX.getValue());
EasyExcel.write(response.getOutputStream(), clazz)
.excelType(ExcelTypeEnum.XLSX)
.registerWriteHandler(handler)
.sheet("Sheet1")
.doWrite(data);
} catch (IOException e) {
throw new GlobalDefaultException(ResponseEnum.ERROR_EXCEL_EXPORT, e);
}
}
提示的异常或者没有达到的效果 下载出来的文件还是xls,然后打开的时候会有提醒