微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/csharp/100141.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐