Open zJohny opened 1 week ago
private static void extracted(HttpServletResponse response,List<HashMap<String, Long>> maps) throws FileNotFoundException { InputStream resourceAsStream = GpCellsController.class.getResourceAsStream("/fill/exceltemplate/模板.xls"); if (resourceAsStream == null) { throw new FileNotFoundException("未找到模板文件"); } try(ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(resourceAsStream).excelType(ExcelTypeEnum.XLS).build()){ if(maps!=null){ maps.forEach(map->{ WriteSheet writeSheet1 = EasyExcel.writerSheet("月报表").build(); excelWriter.fill(map, writeSheet1); }); } String fileNamedownload = "详细信息" + System.currentTimeMillis()+".xls"; log.info("生成的报表名:{}",fileNamedownload); response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); String fileName1= URLEncoder.encode(fileNamedownload,"UTF-8").replaceAll("\+","%20"); response.setHeader("Content-disposition","attachment;filename*=utf-8''"+fileName1); excelWriter.finish(); } catch (IOException e) { throw new RuntimeException(e); }
代码无报错,本地测试无误,部署到Linux上就会出现扩展名无效的现象,而且我设置的后缀是.xls,下载下来就变成.xlsx
下载下来之后,文件名也不正常,应该是“负债表1732104616044.xls”,而实际上是“负债表.xls”,时间戳也没有了
问题已解决,不是easy excel的问题,是我们前端把文件流重新命名了。
异常代码
private static void extracted(HttpServletResponse response,List<HashMap<String, Long>> maps) throws FileNotFoundException { InputStream resourceAsStream = GpCellsController.class.getResourceAsStream("/fill/exceltemplate/模板.xls"); if (resourceAsStream == null) { throw new FileNotFoundException("未找到模板文件"); } try(ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(resourceAsStream).excelType(ExcelTypeEnum.XLS).build()){ if(maps!=null){ maps.forEach(map->{ WriteSheet writeSheet1 = EasyExcel.writerSheet("月报表").build(); excelWriter.fill(map, writeSheet1); }); } String fileNamedownload = "详细信息" + System.currentTimeMillis()+".xls"; log.info("生成的报表名:{}",fileNamedownload); response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); String fileName1= URLEncoder.encode(fileNamedownload,"UTF-8").replaceAll("\+","%20"); response.setHeader("Content-disposition","attachment;filename*=utf-8''"+fileName1); excelWriter.finish(); } catch (IOException e) { throw new RuntimeException(e); }
异常提示
代码无报错,本地测试无误,部署到Linux上就会出现扩展名无效的现象,而且我设置的后缀是.xls,下载下来就变成.xlsx
问题描述
下载下来之后,文件名也不正常,应该是“负债表1732104616044.xls”,而实际上是“负债表.xls”,时间戳也没有了