web端调用Webapi获取Excel表格


首先定义方法的返回值需要为HttpResponseMessage

定义返回的对象

var response = new HttpResponseMessage();

定义一个流接收

MemoryStream StreamFile=//加载的数据

接下来是处理

                response.Content = new StreamContent(StreamFile);
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
                response.Content.Headers.ContentDisposition.FileName = "导出的Excel名称.xls";

                return response;

接下来是JavaScript代码

window.location=APIURL+"/api/report/excels";

调用之后,浏览器便会把这个Excel下载了

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM