• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Export to excel question

 
Nagaraju Nookala
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've jsp file that will extract data from the database and export it to excel file. Browser will have a popup that prompt the user with a "Save As" prompt.

The problem I'm having is that for the file name, the browser is using the name of the servlet (say "Copy of Example.do" as the file name).

So my question is how do I get the correct file name to show up. I'm trying to get this to work for the IE 6 browsers.

The headers are being set as follows:

response.setContentType("application/vnd.ms-excel");
response.addHeader("Content-Disposition", "inline; filename=\""+fileName+"\"");

Any help would be appreciated.

Thanks,
Nookala
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Servlets forum as this is not a JSP issue.
 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this before setting the content type


instead of this

 
Peter Rooke
Ranch Hand
Posts: 851
1
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and if you wish to do more complex things look at the Apache POI Project, in particular the HSSF Page
 
Nagaraju Nookala
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. If I use,
response.addHeader("Content-Disposition", "attachment; filename=\""+fileName+"\"");
I can open the file in a new window but not in the current window. The file opened in the new window will have the name with a (1) at the end as the filename (say filename(1)). Is there a way to fix this? When I download the file and hit "save" button on the "open-save-cancel" dialog it saves the file with correct name. If I hit "open" button and use File>Save As... I am having the problem.

Thanks,
Nookala.
 
Harsha Pherwani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone resolved this issue of the naming convention? I am facing a similar situation now.

Here is my code in JSP:
<%@ page contentType="application/vnd.ms-excel" %>
<% response.setHeader("Content-Disposition", "attachment; filename=\"abc.xls\""); %>

When this code is executed, an open save dialog box opens up. If I hit save, it saves my file correctly as "abc.xls" BUT if I hit open, it opens the excel file with name "abc[1].xls" and the sheet name is ".xls]abc[1]".
Due to this, when user hits save on the excel sheet, it fails saying there shouldn't be any special characters like "[", "]". User has to now rename the file to save it (which I dont want).

This issue is only with IE. I'm using IE6 version currently. Firefox opens and saves it correctly.

If anyone can throw some light as to what I should do to resolve this and have the file name be correct as specified with the trailing numbers ans brackets and not have the user to rename the file and then save, it'll be great!

Thanks in advance.

Harsha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic