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

我使用CarlosAG-Dll为我创建一个 XML-Excel文件(在MemoryStream中).
Response.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类型(但是哪一个?).

编辑:我发现了一个错误描述here

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

解决方法

像这样使用
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类型列表

Office 2007 File Format MIME Types

编辑:

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:

06002

有关详细信息,请参阅this link

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...