Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to give seperate file names for xls reports genetared usinf POI  RSS feed

 
amitava guha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am using apache POI to generate reports in excel format which will be displayed in Internet Explorer window.
I am creating the excel file in a folder and reading that from my action page and displaying it in IE using response.setContentType("application/vnd.ms-excel");

Because of this every time I generate a report the name of the file is shown as Report.do for all reports. How can I set the file name?

Any help will be appreciated.
Thanks
Amit
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you setting a Content-Disposition header? Something like:

response.setHeader("Content-Disposition", "inline; filename=\"spreadsheet.xls\"");
 
amitava guha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
Although I am setting the header that you have given

response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "inline; filename=\"spreadsheet.xls\"");

Still I am getting the file name as "Copy of SAOReport.do" when trying to save it. The below address is showing in the IE address bar.

http://127.0.0.1:9080/ServicePlatformWeb/SAOReport.do

Is there a solution for this?
 
amitava guha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

After setting the header as

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

I am getting a popup saying download file which has option to Open/Save/Cancel. If I save the file then it get saved with the report name [reportEntity.getReportName()] but if I click Open then it is opening in IE and then if I try to do save as, it shows "Copy of Reports.do" as file name.

Is there any way this can be resolved?

Regards,
Amit.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!