我有一个生成 Microsoft Excel 2003 XML 格式电子表格的 ASP.Net MVC 站点。电子表格看起来不错,控制器和视图都可以工作,但文件无法在 Excel 中打开。它在浏览器中打开,因为它是一个 XML 文档。
我尝试将 ContentType 更改为 Excel XLS 格式(应用程序/excel),这使 Excel 打开了文件,但它给出了一条警告消息,指出该文件是 XML 文档,而不是 XLS 文档。
如何从网站在 Excel 中打开 Excel XML 文档?
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %><%
this.Context.Response.Clear();
this.Context.Response.AddHeader("content-disposition", "attachment;filename=State_Report_" + this.ViewData["State"] + ".xml");
this.Context.Response.Charset = "";
this.Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
this.Context.Response.ContentType = "application/excel";
%><?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">