我想知道如何从我的 AngularJS 应用程序中下载可下载的报告?
我想要的是一个可下载的文件,或者.xlsx
在预览中的其他选项卡中打开 Excel Online。
我怎么能那样做?
我通常建议创建一个隐藏表单并将普通的 http 提交到 jsreport /api/report。这是最稳定的方式,适用于所有浏览器。
<form method='POST' target='_blank' action='/api/report' id='jsrForm'>
<input hidden='true' name='template[shortid]' value="41ucBgXKe"/>
<input hidden='true' name='data[foo]' value="Hello world"/>
<input hidden='true' name='options[Content-Disposition]' value="attachment; filename=myreport.pdf"/>
</form>
<script>
document.getElementById("jsrForm").submit();
</script>
你能控制反应吗?如果是这样,请将 content-disposition 标头和 MediaType 标头添加到响应中:
对于 System.Net.Http.HttpResponseMessage
var response = new HttpResponseMessage{Content = ...........}
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") {
FileName = "mydoc.xlsx"
};
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
对于 System.Net.WebClient
var client = new WebClient();
client.Headers.Add("Content-disposition", "attachment");
client.Headers.Add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");