触发场景描述 下载文件,没有文件后缀 系统:mac OS 10.15.6 (19G73)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36
触发Bug的代码
// String fileName = "房间导入模板" + ".xlsx";
response.reset();
// String contentType = Mimetypes.getInstance().getMimetype(fileName);
response.addHeader(HttpHeaders.CONTENT_TYPE,"application/vnd.ms-excel");
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
//
// if ( ServletUtils.getRequest().getHeader("User-Agent").toLowerCase().indexOf("firefox") > 0) {
// fileName = new String(fileName.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1) ;//firefox浏览器
// } else{
// fileName = URLEncoder.encode(fileName, "UTF-8");
// }
String fileName = URLEncoder.encode("测试", "UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
// response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=\"" +fileName+"\"");
EasyExcel.write(response.getOutputStream(), ExcelHouseTemplateBO.class).registerWriteHandler(new HouseSheetWriteHandler(communityDataDictionaryService)).sheet("模板").doWrite(result);
提示的异常或者没有达到的效果