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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/csharp/100141.html

猜你在找的C#相关文章