Setting mime type for excel document

MS Excel has the following observed MIME types:

  • application/vnd.ms-excel (official)
  • application/msexcel
  • application/x-msexcel
  • application/x-ms-excel
  • application/x-excel
  • application/x-dos_ms_excel
  • application/xls
  • application/x-xls
  • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (xlsx)
  • Is there any one type that would work for all versions? If not, do we need to set response.setContentType() with each one of these mime types individually?

    Also, we use file streaming in our application to display document (not just excel - any type of document). In doing so, how can we retain the filename if the user opts to save the file - currently, the name of the servlet that renders the file appears as the default name.


    I believe the standard MIME type for Excel files is application/vnd.ms-excel .

    Regarding the name of the document, you should set the following header in the response:

    header('Content-Disposition: attachment; filename="name_of_excel_file.xls"');
    

    Waking up an old thread here I see, but I felt the urge to add the "new" .xlsx format.

    According to http://filext.com/file-extension/XLSX the extension for .xlsx is application/vnd.openxmlformats-officedocument.spreadsheetml.sheet . It might be a good idea to include it when checking for mime types!


    如果您想以xlsx格式提供excel文件,则应始终使用以下MIME类型

    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 
    
    链接地址: http://www.djcxy.com/p/1270.html

    上一篇: .NET中的文件扩展名和MIME类型

    下一篇: 为Excel文档设置MIME类型