425

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.

Jordy van Eijk
  • 2,718
  • 2
  • 19
  • 37
Subramanian
  • 5,552
  • 5
  • 25
  • 24
  • 6
    More generally, the best way to find out what MS themselves think is the correct type is to find a box with the latest version installed and look at `HKCR/.xls` 's `Content Type` value in the registry. – Rup Jul 26 '12 at 11:48
  • 4
    "application/vnd.ms-office" is another mime type for XLS files. – herrjeh42 Jun 30 '14 at 19:10
  • `application/vnd-xls` also works for `.xls` files. – mbomb007 May 25 '16 at 16:27
  • 1
    Please refer to [this](https://stackoverflow.com/a/4212908/465053) post for complete list of MIME types and related excel file extensions. – RBT Jan 24 '18 at 07:18
  • 1
    The standard excel MIME type is:- application/vnd.ms-excel – Raksha Saini Aug 31 '20 at 05:56

6 Answers6

392

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"');
Callum Watkins
  • 2,844
  • 4
  • 29
  • 49
jbochi
  • 28,816
  • 16
  • 73
  • 90
  • 23
    what is the difference between application/msexcel and application/vnd.ms-excel? – Thabiso Mofokeng Nov 28 '12 at 13:23
  • 7
    If you're wanting to display the document within the browser (if supported) then Content-Disposition needs to be 'inline'. See http://stackoverflow.com/questions/1395151/content-dispositionwhat-are-the-differences-between-inline-and-attachment – flash Oct 01 '13 at 23:15
  • 4
    You should avoid using Content-Disposition in HTTP, it has security considerations. Content-Disposition is only for email. See http://stackoverflow.com/questions/1012437 for more info. – Dzmitry Lazerka Apr 25 '14 at 21:32
  • Note that for OpenXML Excel XLSX file format a different Mime type is defined, see the full list at the link provided. – Oskar Berggren May 07 '15 at 22:44
  • @DzmitryLazerka what is the "secure" alternative to content-disposition? Following your link, then the link in that answer, then the link in that document, gets us to here: http://tools.ietf.org/html/rfc6266#section-4.3. As far as I can tell, the security concern is just involving filenames provided by users--if they contain non-latin characters, or characters that are invalid on some OS. All the major browsers have safeguards against these concerns. Windows and Mac also set a flag on a file indicating that it came from the internet, popping up a warning when you try to open it. – Kip Oct 13 '15 at 13:56
  • @Kip Not only bad characters, but also Javascript, there was a link in that question comments on content-disposition hacking. – Dzmitry Lazerka Oct 14 '15 at 17:05
  • Secure alternative is to make URL to download that ends on desired filename, I believe. – Dzmitry Lazerka Oct 14 '15 at 17:06
211

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!

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Karlis Rode
  • 3,643
  • 2
  • 16
  • 16
  • 3
    This was what I was looking for thanks, needed to support the latest format as well as the previous. – Lee Mar 15 '18 at 12:26
61

For .xls use the following content-type

application/vnd.ms-excel

For Excel 2007 version and above .xlsx files format

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Du-Lacoste
  • 11,530
  • 2
  • 71
  • 51
9

I was setting MIME type from .NET code as below -

File(generatedFileName, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")

My application generates excel using OpenXML SDK. This MIME type worked -

vnd.openxmlformats-officedocument.spreadsheetml.sheet
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
2

I am using EPPlus to generate .xlsx (OpenXML format based) excel file. For sending this excel file as attachment in email I use the following MIME type and it works fine with EPPlus generated file and opens properly in ms-outlook mail client preview.

string mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
System.Net.Mime.ContentType contentType = null;
if (mimeType?.Length > 0)
{
    contentType = new System.Net.Mime.ContentType(mimeType);
}
Vishwajit G
  • 510
  • 4
  • 9
1

For anyone who is still stumbling with this after using all of the possible MIME types listed in the question:

I have found that iMacs tend to also throw a MIME type of "text/xls" for XLS Excel files, hope this helps.

be_es
  • 41
  • 1