asp.net core service return FileContentResult as this format: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
How Can I open on desktop or download on browser the excel file?
Backend
[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);
}
}
Frontend
$.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")
}
});
}