Home SALESFORCE How to make the Reports like Excel, PDF, Word, CSV using Visualforce

How to make the Reports like Excel, PDF, Word, CSV using Visualforce

We can make the different types of Reports using visualforce page.

Example:

<apex:page renderAs=”pdf”>
<style> body { font-family: Arial Unicode MS; } </style>
<h1>Congratulations</h1>
<p>This is your new PDF</p>
</apex:page>

add ‘PDF’ in the RenderAs attributes.

Note: contentType Attributes

The MIME content type used to format the rendered page. Possible values for this attribute include “text/html”, “image/png”, “image/gif”, “video/mpeg”, “text/css”, and “audio/basic”. For more information, including a complete list of possible values, see the W3C specifications. You can also define the filename of the rendered page by appending a # followed by the file name to the MIME type. For example, “application/vnd.ms-excel#contacts.xls”. Note: some browsers will not open the resulting file unless you specify the filename and set the cache attribute on the page to “true”.

Excel:
For this report, creating an HTML table will work to render the data in its appropriate columns and rows. You may also use apex:pageBlockTable, apex:repeat, apex:dataTable, etc.The “#report.xls” tagged at the end of the contentType string will be the name of your file. Also, you have to set cache=”true” for IE support.

contentType="application/vnd.ms-excel#report.xls" cache="true">

Word:
Same as the Excel file, the “#report.doc” tagged at the end of the contentType string will be the name of your file. Again, you have to set cache=”true” for IE support.

contentType="application/msword#report.doc" cache="true">

This tag helps you control your page breaks:

 

PDF: If you’re using apex:pageBlock, etc, the Salesforce theme will not display in the PDF, including the nice rounded page borders, colors, or headers. It’ll just appear as different-sized fonts with different weights, etc.

renderAs="pdf">

CSV:
Note that this page has to be completely clean and display only text that would be accepted in a .csv file. Even using something as basic as “apex:repeat” tend to insert breaks, spaces, and formatting that would be disruptive if you are using the csv file for an upload process that may be fussy. I’ve found that the best way to do this is to format your entire csv text within your controller class into a string variable, and display just the string in the VisualForce page using {!string} or apex:outputText.

The “#report.xls” tagged at the end of the contentType string will be the name of your file.

contentType="text/csv#report.csv">

Source:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_styling_content_type.htm
http://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_renderas_pdf.htm
http://theviewfromouthere.wordpress.com/2009/10/08/turning-a-visualforce-page-into-a-word-document/

You may also like

Leave a Comment