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

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


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

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/”. Note: some browsers will not open the resulting file unless you specify the filename and set the cache attribute on the page to “true”.

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/" cache="true">

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.


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.



Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply

Your email address will not be published. Required fields are marked *