2

I am getting the result set in servlet and then forwarding to the JSP page where I put all data from resultset to table and then getting output to excel file. in the top of my JSP page I have

response.setContentType("application/vnd.ms-excel;");

filename="Report";
filename+=".xls";
response.addHeader("Content-Disposition","attachment; filename="+filename);

The problem is it is downloading data in excel sheet but default as web page so whenever i download the data i have to manually change the save as type to Excel workbook. and also when i download to excel it is warning me that file is not in XLS format whether you want to open it not.

Is there any way I can do like whenever I download the data in excel it will say Excel workbook in save as type?

informatik01
  • 16,038
  • 10
  • 74
  • 104
user1847801
  • 27
  • 1
  • 2
  • 5
  • Depending on your excel version, take a look at this: http://stackoverflow.com/questions/2937465/what-is-correct-content-type-for-excel-files – Sotirios Delimanolis Apr 15 '13 at 18:54
  • well i am able to download on excel but only problem is it is giving me warnings that the file i am downloading which is 'report.xls' is in different format then excel. and after i save clicking ok it is giving me excel file with default save as type 'web page' – user1847801 Apr 15 '13 at 19:50
  • See response http://stackoverflow.com/a/1764035/33622 – fglez Apr 16 '13 at 15:24

1 Answers1

0
Use response.setHeader() instead of response.addHeader()
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=filename.xls");
piyush
  • 139
  • 3