[英]How to receive blob response for downloading excel file in Angular
我想使用 angular 在 excel 文件中下載 model,這是服務的代碼 ZC1C425268E68385D1AB507:
getExcelReport(data: myModel[]): Observable<Blob> {
let params = new HttpParams()
.set('myParam', JSON.stringify(data));
return this.Http.get(this.url + '/MyController/GetExcelReport', { params: params, observe: "body", responseType: "blob" });
當我調用它時,我得到一個錯誤:415(不支持的媒體類型)。 我知道要使用的正確語法嗎? 謝謝
感謝您的幫助,是的,我只想下載它。我找到了這個解決方案:
getExcelReport(data: myModel[]): void {
const url: string = this.url + '/MyController/GetExcelReport';
this.Http.post(url, data, { responseType: 'blob' })
.subscribe((response: Blob) => saveAs(response, `report.xlsx`));
}
在 API 中:
[HttpPost] [Route("GetExcelReport")] public async Task<IActionResult> GetExcelReport([FromBody] IList<myModelType> myModel)
它對我有用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.