C# 导出到 Excel .xlsx 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10436485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exporting to Excel .xlsx file
提问by TMan
How can I export an .xlsx file to excel through mvc using chrome. It works for .xls but not .xlsx
如何使用 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();
采纳答案by Filburt
Check your MIME-Types in IIS - the webserver is not aware of the Office 2007 (and higher) file extensions and refuses to serve them.
检查 IIS 中的 MIME 类型 - 网络服务器不知道 Office 2007(及更高版本)文件扩展名并拒绝为它们提供服务。
See Register the 2007 Office system file format MIME types on serverson TechNet on this topic.
有关此主题,请参阅在 TechNet 上的服务器上注册 2007 Office system 文件格式 MIME 类型。
Even if you're not using "real" IIS you should try adding the xslx MIME type to your web.config:
即使您没有使用“真正的”IIS,您也应该尝试将 xslx MIME 类型添加到您的 web.config:
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".xslx" mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
</staticContent>
</system.webServer>
</configuration>

