MIME-Type for Excel XML (ASP.NET 3.5)

前端 未结 3 490
终归单人心
终归单人心 2020-12-19 05:50

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

Response.ContentType = \"application/vnd.ms-excel\";
Response.AppendHeader(         


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-19 06:42

    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

    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    
    Response.AppendHeader("content-disposition", "attachment; filename=myfile.xlsx");
    

    See list of MIME types

    Office 2007 File Format MIME Types

    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:

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

    For more details see this link

提交回复
热议问题