• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Export to excel question

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to the Servlets forum as this is not a JSP issue.
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this before setting the content type


instead of this

 
Bartender
Posts: 1155
20
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic