产生Asp.net MVC Web站点的Excel XML文档 [英] Generate an Excel XML document in Asp.net MVC Web Site

查看:169
本文介绍了产生Asp.net MVC Web站点的Excel XML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成一个Microsoft Excel 2003 XML格式的小号preadsheet一个ASP.Net MVC的网站。在S preadsheet看起来不错,控制器和视图都工作,但该文件将不会在Excel中打开。它在浏览器中打开,因为它是一个XML文档。

我试图改变的ContentType是Excel的XLS格式(应用/ Excel文件),这让Excel中打开该文件,但它给出了一个警告消息,该文件是一个XML文档,而不是一个XLS文件。

如何从一个网站做在Excel中打开一个Excel XML文档?

 <%@页面语言=C#继承=System.Web.Mvc.ViewPage%GT;<%
this.Context.Response.Clear();
this.Context.Response.AddHeader(内容处置,附件;文件名= State_Report_+ this.ViewData [国家] +的.xml);
this.Context.Response.Charset =;
this.Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
this.Context.Response.ContentType =应用程序/ EXCEL;
%GT;< XML版本=1.0&GT?;
< MSO的应用程序id =Excel.Sheet&GT?;
<工作簿的xmlns =瓮:架构 - 微软-COM:办公室:■preadsheet
  的xmlns:O =瓮:架构 - 微软-COM:办公室:办公室
  的xmlns:X =瓮:架构 - 微软-COM:办公室:EXCEL
  的xmlns:SS =瓮:架构 - 微软-COM:办公室:■preadsheet
  的xmlns:html =htt​​p://www.w3.org/TR/REC-html40>


解决方案

您的问题可能是使用的文件扩展名的.xml,您是在为你的头增加。
我的code,做同样的事情没有一个文件扩展名的。

您可以尝试下探的.xml扩展或者改变它为.xls或.csv。

I have an ASP.Net MVC site that generates a Microsoft Excel 2003 XML formatted spreadsheet. The spreadsheet looks good, the controller and views both work, but the file won't open in Excel. It opens in the browser because it is an XML document.

I tried changing the ContentType to be the Excel XLS format (application/excel) and that made Excel open the file but it gives a warning message that the file is an XML document, not an XLS document.

How do you make an Excel XML document open in Excel from a web site?

<%@ 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">

解决方案

Your problem may be in using the file extension .xml, which you're adding in your header. My code that does this same thing does not have a file extension at all.

You might try dropping that .xml extension, or changing it to .xls or .csv.

这篇关于产生Asp.net MVC Web站点的Excel XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆