恩蓝号

java无法读取到项目的配置文件,java文件格式问题

java下载的excel文件,打开时告警:

解决方法是:
1、 创建工作薄的时候,用Workbook workbook = new XSSFWorkbook();
设置正确的response头信息,

response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");response.addHeader("Content-Disposition", "attachment;filename=" + new String("激励补发模板".getBytes("UTF-8"), "iso-8859-1") + ".xlsx");

2、创建工作薄的时候,用Workbook workbook = new HSSFWorkbook();

response.setContentType("application/vnd.ms-excel");response.addHeader("Content-Disposition", "attachment;filename=" + new String("激励补发模板".getBytes("UTF-8"), "iso-8859-1") + ".xls");

一定要正确设置response头中的content-type;即设置正确的mime type,具体设置如下:

ExtMIME Type.docapplication/msword.dotapplication/msword.docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document.dotxapplication/vnd.openxmlformats-officedocument.wordprocessingml.template.docmapplication/vnd.ms-word.document.macroEnabled.12.dotmapplication/vnd.ms-word.template.macroEnabled.12.xlsapplication/vnd.ms-excel.xltapplication/vnd.ms-excel.xltapplication/vnd.ms-excel.xlaapplication/vnd.ms-excel.xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet.xltxapplication/vnd.openxmlformats-officedocument.spreadsheetml.template.xlsmapplication/vnd.ms-excel.sheet.macroEnabled.12.xltmapplication/vnd.ms-excel.template.macroEnabled.12.xlamapplication/vnd.ms-excel.addin.macroEnabled.12.xlsbapplication/vnd.ms-excel.sheet.binary.macroEnabled.12.pptapplication/vnd.ms-powerpoint.potapplication/vnd.ms-powerpoint.ppsapplication/vnd.ms-powerpoint.ppaapplication/vnd.ms-powerpoint.pptxapplication/vnd.openxmlformats-officedocument.presentationml.presentation.potxapplication/vnd.openxmlformats-officedocument.presentationml.template.ppsxapplication/vnd.openxmlformats-officedocument.presentationml.slideshow.ppamapplication/vnd.ms-powerpoint.addin.macroEnabled.12.pptmapplication/vnd.ms-powerpoint.presentation.macroEnabled.12.potmapplication/vnd.ms-powerpoint.presentation.macroEnabled.12.ppsmapplication/vnd.ms-powerpoint.slideshow.macroEnabled.12

免责声明:文章源自网络,版权归原作者所有,如有侵犯联系删除。

当前位置:首页 > 编程知识 » 2023-03-03 12:08:14

猜你喜欢