Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zJohny opened this issue Nov 22, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@zJohny
Copy link

zJohny commented Nov 22, 2024

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

@zJohny zJohny added the help wanted Extra attention is needed label Nov 22, 2024
@zJohny
Copy link
Author

zJohny commented Nov 22, 2024

问题已解决,不是easy excel的问题,是我们前端把文件流重新命名了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant