Reputation: 4122
How can I export an .xlsx file to excel through mvc using chrome. It works for .xls but not .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();
Upvotes: 2
Views: 45187
Reputation: 18082
Check your MIME-Types in IIS - the webserver is not aware of the Office 2007 (and higher) file extensions and refuses to serve them.
See Register the 2007 Office system file format MIME types on servers on TechNet on this topic.
Even if you're not using "real" IIS you should try adding the xslx MIME type to your web.config:
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".xslx" mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
</staticContent>
</system.webServer>
</configuration>
Upvotes: 3