Change the MIME type of Your Visualforce Page
You can specify a different format for a Visualforce page by using the contentType attribute on the <apex:page> tag. This sets the HTTPContent-Type header for the response to the value of the
page’s contentType attribute.
The contentType attribute takes a Multipurpose Internet Mail Extension (MIME) type as a value, such as application/vnd.ms-excel, text/csv, or image/gif.
For example, to display Visualforce page data in a Microsoft Excel spreadsheet,
use the contentType attribute on the
<apex:page> tag. Specify a value
of application/vnd.ms-excel.
This Visualforce page builds a list of cases by using static HTML and the
<apex:repeat>
component.
<!-- This page must be accessed with an Account Id in the URL. For example:
https://MyDomainName--c.vf.force.com/apex/myPage?id=001D000000JRBet -->
<apex:page standardController="Account" contentType="application/vnd.ms-excel">
<table border="0" >
<caption>Cases</caption>
<tr>
<th>Case Number</th>
<th>Origin</th>
<th>Creator Email</th>
<th>Status</th>
</tr>
<apex:repeat var="cases" value="{!Account.Cases}">
<tr>
<td>{!cases.CaseNumber}</td>
<td>{!cases.Origin}</td>
<td>{!cases.Contact.email}</td>
<td>{!cases.Status}</td>
</tr>
</apex:repeat>
</table>
</apex:page>