i need to generate Excel , when user clicks on icon in browser.... in servlet i am using this code.. to generate Excel response.setContentType("application/vnd.ms-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 ]
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.