Excel XML的MIME类型(ASP.NET 3.5)

时间:2021-06-01 21:23:51

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

我使用CarlosAG-Dll为我创建一个XML-Excel文件(在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.

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

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

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

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

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


edit: I found a bug description here

I wonder if this is still open and why?

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

3 个解决方案

#1


6  

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

对于Excel 2007及更高版本,MIME类型不同

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

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

See list of MIME types

请参阅MIME类型列表

Office 2007 File Format MIME Types

Office 2007文件格式MIME类型

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:

如果内容不是本机Excel文件格式,而是基于文本的格式(例如CSV,TXT,XML),则网站可以将以下HTTP标头添加到其GET响应中,以告知IE使用备用名称,并在名称中,您可以将扩展名设置为正确的内容类型:

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

For more details see this link

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

#2


0  

The security warning is NOT about the MIME type - it is a client-side security setting you can't disable from the server side !

安全警告不是关于MIME类型 - 它是客户端安全设置,您无法从服务器端禁用!

Another point - change Response.AppendHeader("content-disposition", "myfile.xml"); to:

另一点 - 改变Response.AppendHeader(“content-disposition”,“myfile.xml”);至:

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

OR

要么

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

For reference see http://www.ietf.org/rfc/rfc2183.txt

有关参考,请参阅http://www.ietf.org/rfc/rfc2183.txt

EDIT - as per comment:

编辑 - 根据评论:

IF the format is not XLSX (Excel 2007 and up) then use myfile.xls in the above code.

如果格式不是XLSX(Excel 2007及更高版本),则在上面的代码中使用myfile.xls。

#3


0  

If your document is an Excel Xml 2003 document, you should use the text/xml content type.

如果您的文档是Excel Xml 2003文档,则应使用text / xml内容类型。

Response.ContentType = "text/xml";

Do not specifiy content-disposition.

不要指定内容处置。

This technichs works great with Handler, not with WebForm.

这种技术适用于Handler,而不适用于WebForm。

#1


6  

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

对于Excel 2007及更高版本,MIME类型不同

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

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

See list of MIME types

请参阅MIME类型列表

Office 2007 File Format MIME Types

Office 2007文件格式MIME类型

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:

如果内容不是本机Excel文件格式,而是基于文本的格式(例如CSV,TXT,XML),则网站可以将以下HTTP标头添加到其GET响应中,以告知IE使用备用名称,并在名称中,您可以将扩展名设置为正确的内容类型:

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

For more details see this link

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

#2


0  

The security warning is NOT about the MIME type - it is a client-side security setting you can't disable from the server side !

安全警告不是关于MIME类型 - 它是客户端安全设置,您无法从服务器端禁用!

Another point - change Response.AppendHeader("content-disposition", "myfile.xml"); to:

另一点 - 改变Response.AppendHeader(“content-disposition”,“myfile.xml”);至:

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

OR

要么

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

For reference see http://www.ietf.org/rfc/rfc2183.txt

有关参考,请参阅http://www.ietf.org/rfc/rfc2183.txt

EDIT - as per comment:

编辑 - 根据评论:

IF the format is not XLSX (Excel 2007 and up) then use myfile.xls in the above code.

如果格式不是XLSX(Excel 2007及更高版本),则在上面的代码中使用myfile.xls。

#3


0  

If your document is an Excel Xml 2003 document, you should use the text/xml content type.

如果您的文档是Excel Xml 2003文档,则应使用text / xml内容类型。

Response.ContentType = "text/xml";

Do not specifiy content-disposition.

不要指定内容处置。

This technichs works great with Handler, not with WebForm.

这种技术适用于Handler,而不适用于WebForm。