本文介绍了如何让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文件可下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!