如何使excel文件可下载 [英] How to make excel file to be downloadable
本文介绍了如何使excel文件可下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经生成了excel报告,我希望用户下载文件,所以如何设置响应属性(内容类型)。
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) .
推荐答案
您需要设置标题和内容类型,如下所示:
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.
编辑:如果需要设置内容长度:
If you need to set the content length:
response.contentLength = 100
内容在 javadoc 中记录的长度
这篇关于如何使excel文件可下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文