如何使用 chrome 通过 mvc 将 .xlsx 文件导出到 Excel。它适用于 .xls,但不适用于 .xlsx
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename= Estimate1.xlsx");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
Response.Write(sw.ToString());
Response.End();
最佳答案
检查 IIS 中的 MIME 类型 - 网络服务器无法识别 Office 2007(及更高版本)文件扩展名并拒绝为其提供服务。
参见Register the 2007 Office system file format MIME types on servers TechNet 上有关此主题的信息。
即使您没有使用“真正的”IIS,您也应该尝试将 xslx MIME 类型添加到您的 web.config:
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".xslx" mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
</staticContent>
</system.webServer>
</configuration>
关于c# - 导出到 Excel .xlsx 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10436485/