+ Start a Discussion

Exporting Data from visualforce using command button.

I created one vf page, I am showing records in pageblock table, now i want to export data to  Excel, whenever click the command button.



plz help me.................


You can create same page as you use to show the data in SF,  only as excel:


<apex:page controller="className" contentType="application/vnd.ms-excel">



The button (in your current page) will open the excel page:

<apex:outputlink target="_blank" value="/apex/ExcelPageName" >
      <apex:outputText value="Export To Excel" />




You do not have to setup a separate page to render the current markup to Excel. You could dynamically change the contenttype to one specified above based on a formula to render this page to excel.