Can not open Export xlsx in ASP.NET Core 4.5.2 in browser using InMemoryReport
I using .Net Standard (not .Net Core) in .Net Framework 4.6.1
Environment
backend: ASP.NET Core EPPlus, .Net Standard (not .Net Core) in .Net Framework 4.6.1
frontend: Chrome, angularjs
The in-use version:
Operating system:
Win7, Visual studio 2017,
## Example code/Steps to reproduce:
1. controller same with code example:
HomeController.InMemoryReport()
{
byte[] reportBytes;
using (var package = createExcelPackage())
{
reportBytes = package.GetAsByteArray();
}
return File(reportBytes, XlsxContentType, "report.xlsx");
}
2. Got web API response in front end to open excel in browser Chrome
response.data is the controller response.
let blob = new Blob([response.data], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
})
//To support IE
if (navigator.appVersion.toString()
.indexOf('.NET') > 0)
window.navigator.msSaveBlob(blob, "report.xlsx");
//To support Chrome
else {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
let url = window.URL.createObjectURL(blob);
a.href = url;
a.download = "report.xlsx";
a.click();
window.URL.revokeObjectURL(url);
}
});
## Output:
But it showed as:
"Excel cannot open the file... because the file format or file extension is not valid. Verify..corrupted and..."
I tried to change blob type to type: 'text/plain', but it does not work.
Summary of the issue
Can not open Export xlsx in ASP.NET Core 4.5.2 in browser using InMemoryReport I using .Net Standard (not .Net Core) in .Net Framework 4.6.1
Environment
backend: ASP.NET Core EPPlus, .Net Standard (not .Net Core) in .Net Framework 4.6.1 frontend: Chrome, angularjs
Exception message: Full Stack trace: