Error while opening a Office 2007 Excel (.xlsx) from a Servlet
843840Oct 7 2008 — edited Apr 29 2010Hi All,
Actually i am trying to open an excel file from a servlet. It works fine when the file format is .xls. But if it is .xlsx it gives the below error.
"The file you are trying to open .xlsx is in a different format than specified by the file extension. verify the file is not corrupted and is from trusted source before opening the file. Do you want to open the file now?"
There is a link in the application. When we click the link it calls the servlet. The servlet calls the DAO. The DAO queries the DB and the whole output is stuffed into a StringBuffer and the StringBuffer is written to the ServletOutputStream. I have used
File newFile = new File("ABC.xslx");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
I have also included the below in the web.xml file.
<mime-mapping>
<extension>xlsx</extension>
<mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type></mime-mapping>
Kindly help me out.
Thanks.