Activity Forums Salesforce® Discussions How to convert visualforce page into excel format in Salesforce?

  • Yogesh

    Member
    September 23, 2019 at 11:14 am

    Hello,

    By simply modifying the ContentType attribute on the <apex:page> tag, your Visualforce page code will automatically generate an Excel document. For example, the following code will create a table of Contact data for a given Account. After # in the contentType attribute value, it is the name of the excel file that will be generated and you also need to mention the file extension like .xls . For successfully running the below code you need to provide the valid account id in URL.

    sample Vf code:-

    <apex:page standardController="Account" contenttype="application/vnd.ms-excel#Demo Example.xls">
    <apex:pageBlock title="Hello {!$User.FirstName}!">
    You are viewing the {!account.name} account.
    </apex:pageBlock>
    <apex:pageBlock title="Contacts">
    <apex:pageBlockTable value="{!account.Contacts}" var="contact">
    <apex:column value="{!contact.Name}"/>
    <apex:column value="{!contact.Email}"/>
    <apex:column value="{!contact.Phone}"/>
    </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:page>

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos