0

我想知道如何从我的 AngularJS 应用程序中下载可下载的报告?

该报告是.xlsx我可以发布数据,但响应是: 回复

我想要的是一个可下载的文件,或者.xlsx在预览中的其他选项卡中打开 Excel Online。

我怎么能那样做?

4

2 回答 2

2

我通常建议创建一个隐藏表单并将普通的 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>
于 2016-01-28T12:21:19.640 回答
0

你能控制反应吗?如果是这样,请将 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");
于 2016-01-27T07:02:58.293 回答