alibaba/easyexcel

填充模板下载excel,后缀是xls,提示:excel无法打开文件,文件格式或扩展名无效

Open

#4052 aperta il 22 nov 2024

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)Java (7599 fork)batch import
help wanted

Metriche repository

Star
 (33.728 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

image

异常代码

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”,时间戳也没有了

Guida contributor