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

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

问题描述

我使用CarlosAG-Dll,它为我创建一个XML-Excel文件(在MemoryStream内)。

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

我的问题是,我在客户端得到一个myfile.xls(IE)或一个myfile .xml.xls(FF),因此从excel得到一个恼人的安全警告。



我也尝试过与application / vnd.openxmlformats-officedocument.spreadsheetml.sheet( xlsx),但是它甚至不会打开。



所以我需要剪切.xml并将其发送为vnd.ms-excel(如何?)或采取另一个MIME类型(但是哪一个?)。



编辑:我发现错误描述这里



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

解决方案

使用这样

  Response.ContentType =application / vnd.ms-EXCEL; 

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

对于Excel 2007及以上,MIME类型不同

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

Response.AppendHeader(content-disposition,attachment; filename = 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.AddHeaderContent-Disposition,Attachment; Filename = myfile.csv


< blockquote>

有关详细信息,请参阅 此链接


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

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

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