Microsoft Excel 2003 XML 形式のスプレッドシートを生成する ASP.Net MVC サイトがあります。スプレッドシートは問題ないように見え、コントローラーとビューの両方が機能しますが、ファイルは Excel で開きません。これは XML ドキュメントであるため、ブラウザで開きます。
ContentType を Excel XLS 形式 (アプリケーション/Excel) に変更しようとしたところ、Excel でファイルが開かれましたが、ファイルが XLS ドキュメントではなく XML ドキュメントであるという警告メッセージが表示されます。
Web サイトから Excel XML ドキュメントを Excel で開くにはどうすればよいですか?
<%@ 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">