Newer Version Available
Using a Custom ContentType
You can specify a different format for a Visualforce page by using the ContentType attribute on the <apex:page> tag. This sets the Content-Type HTTP header for the response to the value of
the page’s ContentType attribute.
The ContentType attribute takes a Multipurpose Internet
Mail Extension (MIME) media type as a value, such as application/vnd.ms-excel, text/csv,
or image/gif.
Microsoft Excel ContentType Example
To display Visualforce page data in a Microsoft Excel spreadsheet, use the contentType attribute on the <apex:page> tag, and specify a value of application/vnd.ms-excel.
For example, the following page builds a simple list of contacts. It’s a simplified version of the example shown in Building a Table of Data in a Page.
To display this page in Excel, add the contentType attribute to the <apex:page> tag, as follows:
If the page doesn’t display properly in Excel, try a different MIME type, such as text/csv.