我使用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类型(但是哪一个?).
我想知道这是否仍然是开放的,为什么?
解决方法
像这样使用
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