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