Content type для excel

I want excel files on a website to open in Excel when clicked, not get saved on desktop, or get opened embedded in a browser etc. Now obviously it all depends on how everything is configured for each user, but what’s the best Content-Type and other settings to achieve just that most of the time?

asked May 30, 2010 at 3:54

taw's user avatar

2

For BIFF .xls files

application/vnd.ms-excel

For Excel2007 and above .xlsx files

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

answered May 30, 2010 at 10:15

Mark Baker's user avatar

Mark BakerMark Baker

208k31 gold badges340 silver badges383 bronze badges

16

answered May 30, 2010 at 3:57

miku's user avatar

mikumiku

179k46 gold badges308 silver badges309 bronze badges

2

Do keep in mind that the file.getContentType could also output application/octet-stream instead of the required application/vnd.openxmlformats-officedocument.spreadsheetml.sheet when you try to upload the file that is already open.

CSchulz's user avatar

CSchulz

10.8k10 gold badges59 silver badges112 bronze badges

answered Feb 26, 2014 at 20:43

DiTap's user avatar

DiTapDiTap

3612 silver badges5 bronze badges

This topic lists the most common MIME types with corresponding document types, ordered by their common extensions.

The following two important MIME types are the default types:

  • text/plain is the default value for textual files. A textual file should be human-readable and must not contain binary data.
  • application/octet-stream is the default value for all other cases. An unknown file type should use this type. Browsers are particularly careful when manipulating these files to protect users from software vulnerabilities and possible dangerous behavior.

IANA is the official registry of MIME media types and maintains a list of all the official MIME types. This table lists important MIME types for the Web:

Extension Kind of document MIME Type
.aac AAC audio audio/aac
.abw AbiWord document application/x-abiword
.arc Archive document (multiple files embedded) application/x-freearc
.avif AVIF image image/avif
.avi AVI: Audio Video Interleave video/x-msvideo
.azw Amazon Kindle eBook format application/vnd.amazon.ebook
.bin Any kind of binary data application/octet-stream
.bmp Windows OS/2 Bitmap Graphics image/bmp
.bz BZip archive application/x-bzip
.bz2 BZip2 archive application/x-bzip2
.cda CD audio application/x-cdf
.csh C-Shell script application/x-csh
.css Cascading Style Sheets (CSS) text/css
.csv Comma-separated values (CSV) text/csv
.doc Microsoft Word application/msword
.docx Microsoft Word (OpenXML) application/vnd.openxmlformats-officedocument.wordprocessingml.document
.eot MS Embedded OpenType fonts application/vnd.ms-fontobject
.epub Electronic publication (EPUB) application/epub+zip
.gz GZip Compressed Archive application/gzip
.gif Graphics Interchange Format (GIF) image/gif
.htm, .html HyperText Markup Language (HTML) text/html
.ico Icon format image/vnd.microsoft.icon
.ics iCalendar format text/calendar
.jar Java Archive (JAR) application/java-archive
.jpeg, .jpg JPEG images image/jpeg
.js JavaScript text/javascript (Specifications: HTML and RFC 9239)
.json JSON format application/json
.jsonld JSON-LD format application/ld+json
.mid, .midi Musical Instrument Digital Interface (MIDI) audio/midi, audio/x-midi
.mjs JavaScript module text/javascript
.mp3 MP3 audio audio/mpeg
.mp4 MP4 video video/mp4
.mpeg MPEG Video video/mpeg
.mpkg Apple Installer Package application/vnd.apple.installer+xml
.odp OpenDocument presentation document application/vnd.oasis.opendocument.presentation
.ods OpenDocument spreadsheet document application/vnd.oasis.opendocument.spreadsheet
.odt OpenDocument text document application/vnd.oasis.opendocument.text
.oga OGG audio audio/ogg
.ogv OGG video video/ogg
.ogx OGG application/ogg
.opus Opus audio audio/opus
.otf OpenType font font/otf
.png Portable Network Graphics image/png
.pdf Adobe Portable Document Format (PDF) application/pdf
.php Hypertext Preprocessor (Personal Home Page) application/x-httpd-php
.ppt Microsoft PowerPoint application/vnd.ms-powerpoint
.pptx Microsoft PowerPoint (OpenXML) application/vnd.openxmlformats-officedocument.presentationml.presentation
.rar RAR archive application/vnd.rar
.rtf Rich Text Format (RTF) application/rtf
.sh Bourne shell script application/x-sh
.svg Scalable Vector Graphics (SVG) image/svg+xml
.tar Tape Archive (TAR) application/x-tar
.tif, .tiff Tagged Image File Format (TIFF) image/tiff
.ts MPEG transport stream video/mp2t
.ttf TrueType Font font/ttf
.txt Text, (generally ASCII or ISO 8859-n) text/plain
.vsd Microsoft Visio application/vnd.visio
.wav Waveform Audio Format audio/wav
.weba WEBM audio audio/webm
.webm WEBM video video/webm
.webp WEBP image image/webp
.woff Web Open Font Format (WOFF) font/woff
.woff2 Web Open Font Format (WOFF) font/woff2
.xhtml XHTML application/xhtml+xml
.xls Microsoft Excel application/vnd.ms-excel
.xlsx Microsoft Excel (OpenXML) application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xml XML application/xml is recommended as of RFC 7303 (section 4.1), but text/xml is still used sometimes. You can assign a specific MIME type to a file with .xml extension depending on how its contents are meant to be interpreted. For instance, an Atom feed is application/atom+xml, but application/xml serves as a valid default.
.xul XUL application/vnd.mozilla.xul+xml
.zip ZIP archive application/zip
.3gp 3GPP audio/video container video/3gpp; audio/3gpp if it doesn’t contain video
.3g2 3GPP2 audio/video container video/3gpp2; audio/3gpp2 if it doesn’t contain video
.7z 7-zip archive application/x-7z-compressed

The content type for .xlsx files is:

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

Or use 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/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

Response.AppendHeader("content-disposition", "attachment; filename=myfile.xlsx");

Or if you are trying to read the file then try this:

DataSet objds = new DataSet();
string ConnStr = "";
if (FileExtension == ".xlsx")
{
    ConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName + ";Extended Properties="Excel 12.0 Xml;HDR=No;IMEX=1";";
}
else
{
    ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileName + ";Extended Properties="Excel 8.0;HDR=No;IMEX=1";";

}
OleDbCommand selectCommand = new OleDbCommand();
OleDbConnection connection = new OleDbConnection();
OleDbDataAdapter adapter = new OleDbDataAdapter();
connection.ConnectionString = ConnStr;
string strSQL = "SELECT * FROM [Sheet1$]";
if (connection.State != ConnectionState.Open)
    connection.Open();
OleDbCommand cmd = new OleDbCommand(strSQL, connection);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(objds);
connection.Close();

All the best.
—Amit

This article describes MIME Types and the corresponding file extension of the Microsoft Office documents. It will very be useful for document analysis, and you can easily define ContentType for the Microsoft Office associated documents in ASP.NET applications. Also you can use this details to customize MIME types in IIS server configuration.

 For Microsoft Office Excel, you can define content type like this example.
 Aspx page
<%response.ContentType=“application/vnd.ms-excel”%>

 C#
  Response.ContentType = “application/vnd.ms-excel”;

The following table lists the MIME types and file extensions that are associated  with the Microsoft Office documents.

Extension MIME Type
.doc application/msword
.dot application/msword
.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx application/vnd.openxmlformats-officedocument.wordprocessingml.template
.docm application/vnd.ms-word.document.macroEnabled.12
.dotm application/vnd.ms-word.template.macroEnabled.12
.xls application/vnd.ms-excel
.xlt application/vnd.ms-excel
.xla application/vnd.ms-excel
.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx application/vnd.openxmlformats-officedocument.spreadsheetml.template
.xlsm application/vnd.ms-excel.sheet.macroEnabled.12
.xltm application/vnd.ms-excel.template.macroEnabled.12
.xlam application/vnd.ms-excel.addin.macroEnabled.12
.xlsb application/vnd.ms-excel.sheet.binary.macroEnabled.12
.ppt application/vnd.ms-powerpoint
.pot application/vnd.ms-powerpoint
.pps application/vnd.ms-powerpoint
.ppa application/vnd.ms-powerpoint
.pptx application/vnd.openxmlformats-officedocument.presentationml.presentation
.potx application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx application/vnd.openxmlformats-officedocument.presentationml.slideshow
.ppam application/vnd.ms-powerpoint.addin.macroEnabled.12
.pptm application/vnd.ms-powerpoint.presentation.macroEnabled.12
.potm application/vnd.ms-powerpoint.template.macroEnabled.12
.ppsm application/vnd.ms-powerpoint.slideshow.macroEnabled.12

Thanks,
Morgan
Software Developer

MIME (Multipurpose Internet Mail Extensions) is a media type used to identify a type of data on the Internet or by applications. Its name contains the word «Internet» but it is not only limited to the Internet.IANA is in charge of standardizing and disseminating these MIME classifications.

There are numerous popular extensions available among them. One of them is the Excel MIME type.

Every mime type is divided into two parts, which are separated by a slash (/).

1 Type is a logical grouping of many MIME types that are similar to one another. All Excel files have an application as a type.

2 SubType is specific to a single file type within the «type«.They are unique within the «type».Some of the subtypes for excel files are: vnd.ms-excel,vnd.openxmlformats-officedocument.spreadsheetml.sheet,vnd.openxmlformats-officedocument.spreadsheetml.template,vnd.ms-excel.sheet.macroEnabled.12 etc.

There are various MIME types for Excel for various Excel-related files and their extensions such as. xls,.xlsx,.xlt,.xla, and so on.

Let’s look at Excel file MIME Type and extension used by them in table format.

Extension  MIME Type (Type / SubType) Kind of Document
.xls application/vnd.ms-excel  Microsoft Excel   
.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet  Microsoft Excel (OpenXML) 
.xltx  application/vnd.openxmlformats-officedocument.spreadsheetml.template Office Excel 2007 template
.xlsm application/vnd.ms-excel.sheet.macroEnabled.12  Office Excel 2007 macro-enabled workbook
.xltm application/vnd.ms-excel.template.macroEnabled.12 Office Excel 2007 macro-enabled workbook template
.xlam application/vnd.ms-excel.addin.macroEnabled.12 Office Excel 2007 macro-enabled add-in
.xlsb application/vnd.ms-excel.sheet.binary.macroEnabled.12 Office Excel 2007 non xml binary workbook

various-format-of-excel-file

fig. various format for saving excel file

Let’s explain them in brief.

1 .xls

.xls is one of the older file extension of Microsoft Excel Spreadsheet.It is created by Excel 97 or Excel 2003. They by default generate .xls format.

MIME Type Supported by .xls file is application/vnd.ms-excel where the application of MIME type and vnd.ms-excel is subtypes and vnd here means vendor-specific which in this case vendor is Microsoft.

If you have an.xls file and want to open it in Excel before prior 2007, you can do so easily because Excel before 2007 recognizes application/vnd.ms-excel and does not require to afford to open it.

Despite the fact that the.xls file format is older, it can be opened in all versions of Excel due to backward compatibility in newer versions.

2 .xlsx

xlsx is the new file extension of the Microsoft Excel Spreadsheet. It is created by Excel 2007 and later versions.

If you create an excel file in Excel 2007 or later, it will be saved with the.xlsx extension by default; however, you can also save the same file in.xls format.xlsx is more secure and better for data storage(ie. smaller file size) than xls.

MIME type for .xlsx file is application/vnd.openxmlformats-officedocument.spreadsheetml.sheet where MIME type is application and subtype is vnd.openxmlformats-officedocument.spreadsheetml.sheet

It is a file format based on Office OPEN XML developed by Microsoft for representing spreadsheets. Because xlsx is an open standard, other software application vendors, such as Google (Google Sheets), can use it to interoperate with their spreadsheet applications.

📑 The last «x» in the xlsx file extension indicates that the file is based on the XML Standard.

You can open Xls file in excel 2007 and later and convert them to xlsx and save it.

3 .xltx 

Microsoft Excel Template files with the. xltx extensions are based on the Office OpenXML file format specifications. It is used to generate a standard template file that can be used to generate XLSX files with the same settings as the XLTX file.

MIME type for .xlsx file is application/vnd.openxmlformats-officedocument.spreadsheetml.template where MIME type is application and subtype is vnd.openxmlformats-officedocument.spreadsheetml.sheet

It is XML based file format developed by Microsoft for representing templates. An XLTX is identical to an XLSX in every way except that Excel creates a new instance of an XLSX if the file opened is an XLTX.

📓 xltx is the replacement for the old .xlt format.

4  .xlsm

An XLSM file is a macro-enabled spreadsheet created by Microsoft Excel that can also be opened with Google Sheets.XLSM files are based on the Office Open XML format, where the last «m» of an xlsm file extension indicates that the file contains macros.Macros can be stored within an xlsm file, allowing users to automate repetitive tasks.

MIME type for .xlsx file is application/vnd.ms-excel.sheet.macroEnabled.12 where MIME type is application and subtype is vnd.ms-excel.sheet.macroEnabled.12

5  .xlam

An XLAM file extension indicates an Excel Macro-Enabled Add-In file, which is used to provide additional functionality for spreadsheets.
It has the following MIME types:application/vnd.ms-excel.template.macroEnabled.12 where MIME type is application and subtype is vnd.ms-excel.template.macroEnabled.12

Because of the file’s purpose, there is built-in macro support in .xlam files.

6 .xlsb

An XLSB file is an Excel Binary Workbook file that stores data in binary rather than XML format. Because they are stored in binary, the read and write times in xlsb files are faster, and they have been found to be useful for very large and complex spreadsheets for this reason. They are also smaller in size than the XLSM format.

MIME type for .xlsx file is application/vnd.ms-excel.sheet.binary.macroEnabled.12 where MIME type is application and subtype is vnd.ms-excel.sheet.binary.macroEnabled.12

FAQ:

How to generate .xls file in C# ?

For generating a .xls file in C# code you have to mention application/vnd.ms-excel MIME types in response header as shown below.

Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("content-disposition", "attachment; filename=sample.xls");

How to generate .xlsx file in C#?

For generating a .xls file in C# code you have to mention application/vnd.openxmlformats-officedocument.spreadsheetml.sheet MIME types in response header as shown below.

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

If you are generating Excel file target to xlsx file then you have to use above.

What is the replacement of the xla format?

Ans: xlam is the replacement for the old .xla format.

This is a list of the MIME Types of all well known and lesser known file formats and kinds of documents from the Microsoft Office family.

You can find the MIME Types in the table ordered by the corresponding application Microsoft Word, Excel, Power Point and Access as well as the extension of the file.

Microsoft Word

Extension MIME-Type
DOC application/msword
DOCX application/vnd.openxmlformats-officedocument.wordprocessingml.document
DOT application/msword
DOTX application/vnd.openxmlformats-officedocument.wordprocessingml.template
DOCM application/vnd.ms-word.document.macroEnabled.12
DOTM application/vnd.ms-word.template.macroEnabled.12
DOCM application/vnd.ms-word.document.macroEnabled.12
DOTM application/vnd.ms-word.template.macroEnabled.12
WORD application/msword
W6W application/msword

Microsoft Excel

Extension MIME-Type
XLS application/msexcel
XLSX application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
XLT application/msexcel
XLTX application/vnd.openxmlformats-officedocument.spreadsheetml.template
XLA application/msexcel
XLW application/msexcel
XLSM application/vnd.ms-excel.sheet.macroEnabled.12
XLSB application/vnd.ms-excel.sheet.binary.macroEnabled.12
XLTM application/vnd.ms-excel.template.macroEnabled.12
XLAM application/vnd.ms-excel.addin.macroEnabled.12

Microsoft PowerPoint

Extension MIME-Type
PPT application/mspowerpoint
PPTX application/vnd.openxmlformats-officedocument.presentationml.presentation
POT application/mspowerpoint
POTX application/vnd.openxmlformats-officedocument.presentationml.template
PPS application/mspowerpoint
PPSX application/vnd.openxmlformats-officedocument.presentationml.slideshow
PPA application/mspowerpoint
PPAM application/vnd.ms-powerpoint.addin.macroEnabled.12
PPTM application/vnd.ms-powerpoint.presentation.macroEnabled.12
PPSM application/vnd.ms-powerpoint.slideshow.macroEnabled.12
POTM application/vnd.ms-powerpoint.template.macroEnabled.12

Microsoft Access

Extension MIME-Type
MDB application/msaccess
ACCDA application/msaccess
ACCDB application/msaccess
ACCDE application/msaccess
ACCDR application/msaccess
ACCDT application/msaccess
ADE application/msaccess
ADP application/msaccess
ADN application/msaccess
MDE application/msaccess
MDF application/msaccess
MDN application/msaccess
MDT application/msaccess
MDW application/msaccess

Other

Extension MIME-Type
CALCX application/vnd.ms-office.calx
HLP (Microsoft Windows Help) application/x-winhelp
MPP (Microsoft Project) application/msproject
THMX application/vnd.ms-officetheme
WRI (Microsoft Write) application/mswrite

I hope, I could help you with this list. If I should have forgotten something, just write a comment.

Like this post? Please share to your friends:
  • Content type for word file
  • Content type for word documents
  • Content type for word document
  • Content type for excel xml
  • Content type for excel files