请检查内容类型和扩展名。你现在有
.xls
和
application/vnd.ms-excel
. 陈述的
xlsx
需要相应的扩展和
ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"`
要添加一点上下文,我在返回
ActionResult
ActionResult ExportAsExcel(object input)
{
var fileData = ExcelExport.CreateExcelContent(input);
if (fileData == null || fileData.Length == 0)
{
ViewData["Message"] = "Could not create export file";
View("Error");
}
// File is of type Controller.File
return File(fileData, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "export.xlsx");
}