El servicio principal de asp.net devuelve FileContentResult con este formato: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
¿Cómo puedo abrir en el escritorio o descargar en el navegador el archivo de Excel?
back-end
[HttpPost] public IActionResult ExportCashBoxReportToExcell(List<string> cashFlowDates) { using (var package = new ExcelPackage()) { var worksheet = package.Workbook.Worksheets.Add("CashBox"); var excelData = package.GetAsByteArray(); var contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; var fileName = "MyWorkbook.xlsx"; return File(excelData, contentType, fileName); } }Interfaz
$.ajax({ async: false, type: "POST", headers: {"Authorization": window.localStorage.getItem('token')}, contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', data: { cashFlowDates }, headers: { "accept": "application/json", "content-type": "application/json", "authorization": "Bearer " + window.localStorage.getItem('token') }, url: '/CashBoxReport/ExportCashBoxReportToExcell', success: (response) => { console.log(response) }, error: (error) => { alert("Hata") } }); }