首页 > 解决方案 > 使用 .NET Core 3 和 React 下载 excel 文件

问题描述

我正在尝试下载一个 excel 文件在我的控制器中我正在这样做:

[HttpGet("downloadExcel")]
public async Task<IActionResult> DownloadExcel()
{

var excel = new DownloadExcel();
var fileMemoryStream = excel.GenerateExcel(await students.GetStudentsExcelDownload());

return File(
    fileMemoryStream,
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    String.Concat("Students Excel.xlsx"));
}

在我的 TypeScript 服务中,我正在这样做:

public async downloadExcel(): Promise<any> {
    const response = await this._httpClient.get<any>(`${this.downloadExcel}`);
    console.log("RESPONSE", response)
    return response;
}

但是当我 cosole.log 时,响应是这样的:

https://i.stack.imgur.com/G87BP.png

怎么下载excel文件?

标签: c#excelreactjs

解决方案


推荐阅读