首先定义方法的返回值需要为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下载了

 

相关文章:

  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2021-05-27
  • 2021-07-20
  • 2022-12-23
  • 2021-11-30
  • 2021-11-30
猜你喜欢
  • 2021-12-17
  • 2021-12-08
  • 2021-12-31
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案