Excel warning : File is in different format than specified by the file extension

送分小仙女□ 提交于 2020-01-04 02:42:06

问题


In my application, I am using apache POI 3.8 for report generation.

The system is working fine and its generating report in xls format.

But when I open the xls file it given me warning before opening the file.

And here is the response type I am using...

response.setHeader("Content-Type", "application/vnd.ms-excel");         
response.setHeader("Content-Disposition","attachment; filename="+xlsFileName+".xls");

I also tried with ...

response.setHeader("Content-Disposition","attachment; filename="+xlsFileName+".xls");
 response.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

But the problem still exist. Here in both of the case If I use file extension as ".xlsx" then Its not giving any warning and works fine.

So can anyone suggest me why it gives warning for MS-Excel 2003 format ??


回答1:


Apache POI uses HSSFWorkbook object for creating xls files and XSSFWorkbook object for xlsx files. Please check what object you used for creating xls.

http://poi.apache.org/spreadsheet/quick-guide.html



来源:https://stackoverflow.com/questions/14272537/excel-warning-file-is-in-different-format-than-specified-by-the-file-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!