How to make excel file to be downloadable
19,606
Solution 1
You need to set the headers and content type like this:
response.setHeader "Content-disposition", "attachment;filename=myExcel.xls"
response.contentType = "application/vnd.ms-excel"
Then stream the content in the response.
Edit: If you need to set the content length:
response.contentLength = 100
Content length documented in the javadoc
Solution 2
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "Attachment;Filename=\"MyFile.xls\"");
Author by
n92
Updated on June 04, 2022Comments
-
n92 almost 2 years
I have generated excel report and i want the file to be downloaded by the user ,so how to set the response properties (content type) .
-
Basilevs almost 13 yearsAs user of the site, I'd like to use benefits of content-length header too.
-
Fakipo almost 4 yearsI am getting gibberish as response when I am trying this. I am getting a downloadable file but in response I am getting gibberish which does not happen when I try the same process with a pdf file.