I generated an excel file with OpenXml 2.7.2 in .NETCoreApp 1.1 and saved it into a project folder. Then in my function I read the bytes and try to return it as a File. I don't get an error, but in the response I just get back the binary. So it seems to work but doesn't get downloaded.
Here is my code:
[HttpGet]
[Route("export")]
public IActionResult Export()
{
return File(System.IO.File.ReadAllBytes(filePath),
contentType: "application/octet-stream",
fileDownloadName: "MySheet.xlsx");
}
If anyone knows how to serve a downloadable excel file in .net core let me know. Any help is appreciated thanks!
UPDATE
I'm not sure the corruption is related to generating the excel file with OpenXml because even when I try to export an empty file that wasn't generated with OpenXml I get the same error message saying "The file is corrupt and cannot be opened". Its also not entirely related to Excel 2016 because I can open other excel files with it fine.
application/vnd.ms-excel.12
orapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
(official MIME types for .xlsx) instead ofapplication/octet-stream
– Lavalley