Below is code that loops over Contact ID and Name fields
=========================================================
To Download PDF VISUALFORCE Page
=========================================================
<apex:page controller="contactquery" renderas="pdf" showheader="false">
<apex:pageblock title="Export Results">
<apex:pageblocktable value="{!cs}" var="contact">
<apex:column value="{!contact.ID}">
<apex:column value="{!contact.Name}">
</apex:column></apex:column></apex:pageblocktable>
</apex:pageblock>
</apex:page>
=========================================================
Download Excel VISUALFORCE Page
=========================================================
<apex:page cache="true" contenttype="application/vnd.ms-excel#SalesForceExport.xls" controller="contactquery">
<apex:pageblock title="Export Results">
<apex:pageblocktable value="{!cs}" var="contact">
<apex:column value="{!contact.ID}">
<apex:column value="{!contact.Name}">
</apex:column></apex:column></apex:pageblocktable>
</apex:pageblock>
</apex:page>
=========================================================
Query Controller (Query the data you need)
=========================================================
public class contactquery{
public List<contact> cs{get; set;}
public contactquery()
{
cs = new List<contact>();
for (Contact c : [Select id, Name from Contact])
{
cs.add(c);
}
}
}
No comments :
Post a Comment