Asked  7 Months ago    Answers:  5   Viewed   36 times

MS Excel has the following observed MIME types:

  • application/ (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/

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"');
Tuesday, June 1, 2021
answered 7 Months ago

I cannot reproduce this with this script:


  header('Content-Type:text/plain; charset=ISO-8859-15');
  echo "This is some text";

However, I can reproduce it with this:


  header('Content-Type:text/plain; charset=ISO-8859-15');
  echo "x00This is some text";

Make sure that your content actually is plain ASCII text...

Saturday, May 29, 2021
answered 7 Months ago

To fix this, add curl option -H 'Content-Type: application/json'

This error is due to strict content-type checking introduced in ElasticSearch 6.0, as explained in this post

Starting from Elasticsearch 6.0, all REST requests that include a body must also provide the correct content-type for that body.

Monday, June 28, 2021
answered 6 Months ago

Use like this

Response.ContentType = "application/";

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


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

Thursday, August 5, 2021
answered 4 Months ago

If I understand what you're trying to do, you want a message with this structure:

      text/plain - a plain text version of the main message body
        text/html - the html version of the main message body
        image/jpeg - an image referenced by the main body
    application/octet-stream (or whatever) - the attachment

That means three nested multipart pieces. You'll need to specify the subtype for each multipart piece other than the default "mixed".

The multipart/mixed and multipart/alternative pieces are relatively straightforward. The multipart/related piece is more complicated and you might want to read RFC 2387 and/or find some other tutorials to help you with that.

You can simplify the structure by getting rid of the multipart/related and just having the html text reference an image somewhere on the internet.

You should also test that a message with this structure is going to be displayed properly by all the mail readers you care about. Some mail readers will do a better job than others with a complicated structure such as this.

Sunday, November 21, 2021
answered 2 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :