Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Write Excel file to browser (client)

 
Pappu Kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet that i use to write a excel file and then send it back to user. So the user can save it
or open it in excel. The problem is how do i give a name to this excel file. Because right now, if the
user chooses to open the excel file (rather than saving it). It takes the name of the file same as the name of the servlet
that was used to create the file...ex : http://localhost:7001/app/CreateExcel.do

Here is the snippet of the servlet . I use POI to create excel file


HSSFWorkbook workBook = CreateExcel.writeMSExcel(list.toArray(), lst); // CreateExcel is my helper class
// Write the output
OutputStream out = response.getOutputStream();
workBook.write(out);
out.flush();
out.close();

Please help....
 
Joe Ess
Bartender
Pie
Posts: 9264
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Servlet forum
 
Julia Reynolds
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to set the header on the servlet response, like below:

response.setHeader("Content-Disposition", "attachment;filename="+fileName);

If you don't want to force the user to download the file, you can use with the inline option:

response.setHeader("Content-Disposition", "inline;filename="+fileName);

Julia
[ November 23, 2004: Message edited by: Julia Reynolds ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic