Saturday, April 19, 2014

How to Render data into MS-Execl using Visualforce?

How to Render data into MS-Execl using Visualforce?

Here i am sending particular account related contact detail to MS-Execl, for this you need mention content-type attribute in <apex:page> tag.

Here is the Example.

<apex:page standardController="Account" sidebar="false" contentType="application/vnd.ms-excel#sfdcsrini_Excel.xls" cache="true">
  
  <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>


in content-type attribute i have mentioned the format as MS-Excel and name of the file as "sfdcsrini_Excel". You have to set cache="true" for IE support.


Finally you need to pass the particular account id in to url
like

https://c.ap1.visual.force.com/apex/msexcel?id=0019000000RMAaF


0 comments:

Post a Comment

 
| ,