+ Start a Discussion
imishraimishra 

Export Reports to Excel

Hi,

I want to implement the standard export and Printable view functionality of reports in a visualforce page.

Can anyone let me know if this is possible.

 

Thanks in advance.

Best Answer chosen by imishra
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

This can be done. Try the following VF page and controller.

 

The below example is used to download the vf page as Excel sheet  for the contact redords details created from today and upto today+7 days. The key thing here is contentType="application/x-excel.xls" and action="{!getcontact}", Should be specified in the page tag.

 

VF page

<apex:page contentType="application/x-excel.xls" controller="excelcontrol"  action="{!getcontact}">

 <apex:DataTable value="{!results}" var="tsk"  >

             <apex:column >

                         {!tsk.Name}

              </apex:column>

             <apex:column >

                         {!tsk.Phone}

            </apex:column>  

            <apex:column >

                         {!tsk.Email}

             </apex:column>   

    </apex:DataTable>

</apex:page>

                

Controller

public class excelcontrol {

public excelcontrol( ) { }

 public  List<Contact> results{get;set;}

 Public List<Contact> getResults() {    

              return results;

  }

 public PageReference getContact()   {

            //Querying the values using those values we got through param    

               results=[Select Name,Email,Phone from Contact where createdDate >=:System.Now() and createdDate <=: System.Now() + 7 ];

return null;            

         }

}

 

 

Hope so this helps you...!

 

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

 

 

 

 

All Answers

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

This can be done. Try the following VF page and controller.

 

The below example is used to download the vf page as Excel sheet  for the contact redords details created from today and upto today+7 days. The key thing here is contentType="application/x-excel.xls" and action="{!getcontact}", Should be specified in the page tag.

 

VF page

<apex:page contentType="application/x-excel.xls" controller="excelcontrol"  action="{!getcontact}">

 <apex:DataTable value="{!results}" var="tsk"  >

             <apex:column >

                         {!tsk.Name}

              </apex:column>

             <apex:column >

                         {!tsk.Phone}

            </apex:column>  

            <apex:column >

                         {!tsk.Email}

             </apex:column>   

    </apex:DataTable>

</apex:page>

                

Controller

public class excelcontrol {

public excelcontrol( ) { }

 public  List<Contact> results{get;set;}

 Public List<Contact> getResults() {    

              return results;

  }

 public PageReference getContact()   {

            //Querying the values using those values we got through param    

               results=[Select Name,Email,Phone from Contact where createdDate >=:System.Now() and createdDate <=: System.Now() + 7 ];

return null;            

         }

}

 

 

Hope so this helps you...!

 

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

 

 

 

 

This was selected as the best answer
NK@BITNK@BIT
You can try this blog..

https://nitinkhunalsalesforce.wordpress.com/2016/10/27/visualforce-export-excel-report-using-remote-action-and-alasql/

You can export excel using javascript remoting, For this you don't need to create additional visualforce page to renderAs excel.