Open Jsp in Excel

I am trying to open JSP file in excel and I get the following message: excel cannot open the file because the file format or file extension is not valid.Verify that the file has not been corrupted and that the file extension matches the format of the file. By the way, I have MS excel 2007.

here's my method:

response.setContentType("application/vnd.ms-excel");

response.setHeader("content-disposition","attachment; filename=Report.xlsx");

Also, I have add the following to web.xml:

<mime-mapping>

<extension>xlsx</extension>

<mime-type>application/vnd.ms-excel</mime-type>

</mime-mapping>

[683 byte] By [IcebergTecha] at [2007-11-27 6:38:25]
# 1
Why is it called .xlsx? Is that required? Have you tried the same file with a .xls format?
nogoodatcodinga at 2007-7-12 18:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Try this.Create another file Report.xls in previous office packages. Its seems you're trying to open a .xlsx file in the MS Office envireonment which doesn't support this file extension. To my understanding the *.xlsx *.docx etc are new file extentions for MS Office( as for example office package which comes with windows vista, or MS office 2007).

You can't open such a file extension like *.xlsx in previous office packages if you did not set the compatibility issues.

hope it helps

aiExa at 2007-7-12 18:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
I called the extension xlsx because I am using MS office 2007 and the extension for this version is different than the previous. Also, I tried xls but it didn't work. Any other thoughts.Thanks you for your reply
IcebergTecha at 2007-7-12 18:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Hi aiEx,

Thank you for replying. I am not sure what you mean by "setting up the compatibility issue". I have added the following to web.xml:

<mime-mapping>

<extension>xlsx</extension>

<mime-type>application/vnd.ms-excel</mime-type>

</mime-mapping>

Also, I have changed the file extension from xlsx to xls, it didn't work either. Any other thoughs.

Thank you again

IcebergTecha at 2007-7-12 18:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

did you try to create your new "Report.xls" file?I suggest not to just rename the "Report.xlsx".Create a new file(just for testing and try creating this file in office 2003 or below not in office 2007) with an *.xls extention.You'll in this case need to change your <extension> element in you web.xml. it should in this case be xls not xlsx.

aiExa at 2007-7-12 18:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Thanks again for replying. I have solved the problem. The issue wasn't with the extension or the report. The way we export jsp into excel is to pass all the parameter in the report to the form that generate the excel spread sheet. One of the parameter has a space that's why when the sql runs doesn't match any data. If you need more clarification please let me know.

IcebergTecha at 2007-7-12 18:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
ok . :-) I am not good at all. I just gave it a thought. I will definitly ask you when I get something similar :-)
aiExa at 2007-7-12 18:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
Hi aiEx,au contraire you are very good the fact that you have tried to help. Thanks again
IcebergTecha at 2007-7-12 18:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
OK, i have the same problem and i am a novice. Wouldnt have a clue what to do to fix this problem. Can anyone enlighten me in laymans terms?
Esradekana at 2007-7-12 18:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
Hi,Sorry I haven't checked my account for two weeks. The issue with my code was When I passed all the parameters I have included a space in one of them. If you post you code I can look at it if you still have problem.
IcebergTecha at 2007-7-12 18:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...