wood burning stoves 2.0*
The moose likes Servlets and the fly likes Servlet excel problems ...urgent help needed Pls. (MARK any help?) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet excel problems ...urgent help needed Pls. (MARK any help?)" Watch "Servlet excel problems ...urgent help needed Pls. (MARK any help?)" New topic

Servlet excel problems ...urgent help needed Pls. (MARK any help?)

kumar raju

Joined: Oct 10, 2003
Posts: 1
i need to generate Excel , when user clicks on icon in browser....
in servlet i am using this code.. to generate Excel
response.setHeader("Content-Disposition", "attachment; filename=" + "test.xls");

PrintWriter pw = response.getWriter();
pw.println(" \t sub1 \t \t \t \t \t sub2\t \t \t \t");
the problem is ..once i click on icon it launches excel appliaction, but could not open the file ...(says file is not found)...but i can save and see the data...(the problem is only with direct opening of the file)...
any help?
[ October 10, 2003: Message edited by: kumar raju ]
[ October 10, 2003: Message edited by: kumar raju ]
[ October 10, 2003: Message edited by: kumar raju ]
Kripal Singh
Ranch Hand

Joined: Jul 26, 2001
Posts: 254
i am not sure you are using the correct code or not . try using the code as shown in sample servlet below

[ October 10, 2003: Message edited by: Kripal Singh ]

# Help an unprivileged kid.<br /> Whatever u do will make a difference...<br /> ...to a child's life & ur own #<br /><a href="http://www.cry.org/" target="_blank" rel="nofollow">www.cry.org/</a>
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

The other option you might try (it's worked for me with great success) is to introduce an intermediary step...

Instead of the click invoking a servlet which generates a file that is instantly streamed back to the browser, instead have that link create a comma-seperated file on your server, and make sure it's got a *.csv extension. Then present the user with a 2nd link that is the 'download' link.

The link to serve this file will cause pretty much any version of IE past 5.0 to open Excel as the default application for files of type *.csv

This gets around the nastiness of having to set content-types, application mime stuff, and not to mention streaming a file back through the response.
Jaime Garcia
Ranch Hand

Joined: Jan 07, 2003
Posts: 38
I had a problem like this one, if you have no-cache and you select to open the file, the browser has to save it in a temp file, but no-cache erase it.
Hope this helps
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
If you want to create the Excel content as something other than a comma or tab separated file, there is a pure Java API for creating and manipulating Excel binaries under the Jakarta project:

"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
I agree. Here's the link: http://aspose.com/file-tools
subject: Servlet excel problems ...urgent help needed Pls. (MARK any help?)
Similar Threads
generating lock cookie
Excel with JBuilder ?
JDBC drivers
Error in excel report generation from jsp
Application Running problem in Panasonic X200