You need to sign in to do that
Don't have an account?
Visualforce report to local excel file
Dear all,
I am trying to pass visualforce report data to excel file .I have given page section as below
<apex:page sidebar="false" showHeader="false" contentType="application/vnd.ms-excel#Report.xls" cache="true" Controller="Thecontroller">
and corrosponding apex class
public pagereference FetchExcelReport()
{
Pagereference Reportpage = new PageReference('/apex/ExcelReport');
Return Reportpage;
}
whenever I am trying to save the code (with ctrl+s) on page editor its asking for saving report.xls file, and that file is containing textbox, picklist, and other fields from visualforce pages. while I want only report rows to be saved in excel and only when I click a export button on report page.
please suggest.
Thanks,
Manish.
Create a separate Visualforce page with a controller that only gets the data you want to export in Excel. In the original Visualforce page, add a new button that will open the new Visualforce page in a new page.
Thanks for the reply Val,
I have written the new page for result fields with following details and in original visualforce added button to extract report
<apex:page sidebar="false" showHeader="false" contentType="application/vnd.ms-excel#Report.xls" cache="true" Controller="Thecontroller">
public pagereference FetchExcelReport()
{
Pagereference Reportpage = new PageReference('/apex/NewPage);
Return Reportpage;
}
There is a search button on original visualforce page
If I click on Extract button before search its working properly and empty excel file is getting created, when i perform search by clicking search button and then click extract button to export report to excel...extract button is not working
can you please guide me what could be the reason.
Thanks,
Manish
Are you passing the searched values from the first page to the second page?
Hi Val,
following is my new page
<apex:page sidebar="false" showHeader="false" Controller="institutectrl" contentType="application/vnd.ms-excel#Report.xls" cache="true" >
<apex:pageBlock >
<apex:pageBlockSection title="Results" id="results" columns="1">
<apex:pageBlockTable value="{!results}" var="r">
<apex:column value="{!r.Studentname__r.First_Name__c}" headerValue="Name"/>
<apex:column value="{!r.coursename__r.Name}" headerValue="Course Name"/>
<apex:column value="{!r.coursename__r.Start_Date__c}" headerValue="Course Start Date"/>
<apex:column value="{!r.coursename__r.End_Date__c}" headerValue="Course End Date"/>
<apex:column value="{!r.coursename__r.Course_Fees__c}" headerValue="Course Fees"/>
<apex:column value="{!r.Studentname__r.Date_of_Joining__c}" headerValue="Joining Date"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
Please suggest how to pass searched value.
Thanks,
Manish
You can either pass the searched text from the first page to the second page or you could pass the list of results. You can add it as variables in the URL.
Hi Val,
strStudentName, strCoursetName, strStartDate,strEndDate are the searched fields and Following are their gettersetter
public String strStudentName{get;set;}
public String strCoursename{get;set;}
public Date strStartDate{get;set;}
public Date strEndDate{get;set;}
I am new to Visualforce and Apex, please guide how to pass searched text from one page to second or how to pass list of result
Thanks,
Manish