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.
Browsers can behave unpredictably if you set an invalid contentType. For information about valid MIME types, see http://www.iana.org/assignments/media-types/.
The contentType attribute accepts any MIME type as a valid value. However, Visualforce supports content conversion of only PDFs, which you can do by specifying a renderAs attribute.
Visualforce doesn’t generate other file formats. It only sets the Content-Type field of the HTTP response header to the specified MIME type. Some file formats, such as .xlsx, can fail to render.
-
For example, to display Visualforce page data in a Microsoft Excel spreadsheet, use the
contentTypeattribute on the<apex:page>tag. Specify a value ofapplication/vnd.ms-excel.This Visualforce page builds a list of cases by using static HTML and the
<apex:repeat>component.If the page doesn’t display properly in Excel, try a different MIME type, such as
text/csv.