Asp.net core 3.x 文件下载
我是把逻辑写在service,然后注册到Controller的
前面DI
private readonly INotificationPublisher _notificationPublisher;
private readonly IWebHostEnvironment _env;
private readonly DingTalkWorkflowService _dingTalkWorkflowService;
private readonly LeaseSettlementSummaryAppService _leaseSettlementSummaryAppService;
public HomeController(INotificationPublisher notificationPublisher, IWebHostEnvironment env,
DingTalkWorkflowService dingTalkWorkflowService,
LeaseSettlementSummaryAppService leaseSettlementSummaryAppService)
{
_notificationPublisher = notificationPublisher;
_env = env;
_dingTalkWorkflowService = dingTalkWorkflowService;
_leaseSettlementSummaryAppService = leaseSettlementSummaryAppService;
}
[HttpGet]
[DontWrapResult]
// [AbpAuthorize]
public async Task<FileResult> DownloadSettlementExcel(Guid settlementId)
{
ExportExcelResultClass exportExcelResultClass = await _leaseSettlementSummaryAppService.ExportSettlementExcel(settlementId);
using (exportExcelResultClass.fileStream)
{
var content = exportExcelResultClass.fileStream.ToArray();
return File(
content,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
exportExcelResultClass.excelFileName);
}
}