Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make excel file to be downloadable

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) .

like image 350
n92 Avatar asked Jan 26 '26 06:01

n92


2 Answers

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

like image 138
Nicolas Modrzyk Avatar answered Jan 27 '26 19:01

Nicolas Modrzyk


response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "Attachment;Filename=\"MyFile.xls\"");
like image 28
Basanth Roy Avatar answered Jan 27 '26 18:01

Basanth Roy