You need to sign in to do that
Don't have an account?
Sujendran Sundarraj 8
export to excel return to original page
Hello Guys,
I have a requirement to export visualforce table to excel.
I create a visualforce page with list of account records and a command button - export to excel. Once the button is clicked it will redirect to similar visualforce page with contenttype ="application/vnd.ms-excel#filename.xls". Excel file is downloading but my problem is it has to redirect to original page.
check my code below,
Vf page(export1):
<apex:page controller="exportexcel" >
<apex:pageBlock title="Records">
<apex:pageBlockTable value="{!rec}" var="r">
<apex:column value="{!r.name}"/>
<apex:column value="{!r.phone}"/>
<apex:column value="{!r.industry}"/>
<apex:column value="{!r.Type}"/>
</apex:pageBlockTable>
<apex:form >
<apex:commandButton value="export to excel" action="{!exportnow}"/>
</apex:form>
</apex:pageBlock>
</apex:page>
Controller:
public class exportexcel {
public PageReference exportnow() {
pagereference pager = new pagereference('/apex/export');
pager.setredirect(true);
return pager;
}
public list<account> rec {get; set;}
public exportexcel(){
rec = [select name, type, industry, phone from account limit 10];
}
}
vfpage: (export):
<apex:page controller="exportexcel" contentType="application/vnd.ms-excel#filename.xls" >
<apex:pageBlock title="Records">
<apex:pageBlockTable value="{!rec}" var="r">
<apex:column value="{!r.name}"/>
<apex:column value="{!r.phone}"/>
<apex:column value="{!r.industry}"/>
<apex:column value="{!r.Type}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Kindly help..
Thank you.
I have a requirement to export visualforce table to excel.
I create a visualforce page with list of account records and a command button - export to excel. Once the button is clicked it will redirect to similar visualforce page with contenttype ="application/vnd.ms-excel#filename.xls". Excel file is downloading but my problem is it has to redirect to original page.
check my code below,
Vf page(export1):
<apex:page controller="exportexcel" >
<apex:pageBlock title="Records">
<apex:pageBlockTable value="{!rec}" var="r">
<apex:column value="{!r.name}"/>
<apex:column value="{!r.phone}"/>
<apex:column value="{!r.industry}"/>
<apex:column value="{!r.Type}"/>
</apex:pageBlockTable>
<apex:form >
<apex:commandButton value="export to excel" action="{!exportnow}"/>
</apex:form>
</apex:pageBlock>
</apex:page>
Controller:
public class exportexcel {
public PageReference exportnow() {
pagereference pager = new pagereference('/apex/export');
pager.setredirect(true);
return pager;
}
public list<account> rec {get; set;}
public exportexcel(){
rec = [select name, type, industry, phone from account limit 10];
}
}
vfpage: (export):
<apex:page controller="exportexcel" contentType="application/vnd.ms-excel#filename.xls" >
<apex:pageBlock title="Records">
<apex:pageBlockTable value="{!rec}" var="r">
<apex:column value="{!r.name}"/>
<apex:column value="{!r.phone}"/>
<apex:column value="{!r.industry}"/>
<apex:column value="{!r.Type}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Kindly help..
Thank you.