gpt4 book ai didi

asp.net-mvc - 在 Asp.net MVC 网站中生成 Excel XML 文档

转载 作者:行者123 更新时间:2023-12-02 17:17:47 26 4
gpt4 key购买 nike

我有一个 ASP.Net MVC 站点,可以生成 Microsoft Excel 2003 XML 格式的电子表格。电子表格看起来不错, Controller 和 View 都可以工作,但文件无法在 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">

最佳答案

尝试使用

Response.ContentType = "application/vnd.ms-excel"

并保留 .XML 扩展名。

关于asp.net-mvc - 在 Asp.net MVC 网站中生成 Excel XML 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1948799/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com