MIME类型为Excel XML(ASP.NET 3.5) [英] MIME-Type for Excel XML (ASP.NET 3.5)

查看:233
本文介绍了MIME类型为Excel XML(ASP.NET 3.5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用CarlosAG的DLL这将创建一个XML功能的Excel文件,我(一个MemoryStream里面)。

  Response.ContentType =应用程序/ vnd.ms-EXCEL;
Response.AppendHeader(内容处置,将myfile.xml);
memory.WriteTo(Response.OutputStream);

我的问题在这里,我得到在客户端上myfile.xls(IE)或myfile.xml.xls(FF),并因此获得从Excel中一个恼人的安全警告。

我的应用程序/ vnd.openxmlformats-officedocument.s preadsheetml.sheet(XLSX)尝试过,以及后来它甚至无法打开。

所以,我需要或者削减的.xml并将其作为vnd.ms-Excel文件(如何?),或者采取另一种MIME类型(但哪一个?)。



编辑:我发现了一个bug描述<一个href=\"http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx\"相对=nofollow>这里

我不知道这仍然是开放的,为什么?


解决方案

使用这样

  Response.ContentType =应用程序/ vnd.ms-EXCEL;Response.AppendHeader(内容处置,附件;文件名= myfile.xls);

有关Excel 2007和上面的MIME类型而不同。

  Response.ContentType =应用程序/ vnd.openxmlformats-officedocument.s preadsheetml.sheetResponse.AppendHeader(内容处置,附件;文件名= myfile.xlsx);

请参阅MIME类型的列表

<一个href=\"http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/05/08/office-2007-open-xml-mime-types.aspx\"相对=nofollow> Office 2007文件格式MIME类型

编辑:


  

如果内容不是天然的Excel文件格式,但是不是一个
  基于文本格式(如CSV,TXT,XML),那么该网站可以添加
  下面的HTTP头的GET响应告诉IE浏览器使用
  备用名称,并在名称可以设置扩展的权利
  内容类型:

  Response.AddHeader内容处置,附件;文件名= myfile.csv


有关详细信息,请参阅 <一个href=\"http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx\"相对=nofollow>此链接

I use CarlosAG-Dll which creates a XML-Excel-file for me (inside a MemoryStream).

Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("content-disposition", "myfile.xml");
memory.WriteTo(Response.OutputStream);

My Problem here is, that I get at client side a myfile.xls (IE) or a myfile.xml.xls (FF) and therefore get an annoying security warning from excel.

I tried it as well with application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (xlsx) but then it won't even open.

So I need to either cut the .xml and send it as vnd.ms-excel (how?) or take another MIME-type (but which one?).


edit: I found a bug description here

I wonder if this is still open and why?

解决方案

Use like this

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

Response.AppendHeader("content-disposition", "attachment; filename=myfile.xls");

For Excel 2007 and above the MIME type differs

Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

Response.AppendHeader("content-disposition", "attachment; filename=myfile.xlsx");

See list of MIME types

Office 2007 File Format MIME Types

EDIT:

If the content is not a native Excel file format, but is instead a text based format (such as CSV, TXT, XML), then the web site can add the following HTTP header to their GET response to tell IE to use an alternate name, and in the name you can set the extension to the right content type:

Response.AddHeader "Content-Disposition", "Attachment;Filename=myfile.csv"

For more details see this link

这篇关于MIME类型为Excel XML(ASP.NET 3.5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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