function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ToddKruseToddKruse 

From a VisualForce Page, click a button and export/save the panelGrid to Excel

I have found multiple posts on how to edit the apex:page line so that when the VF page is activated, it saves itself to an excel file:

 

<apex:page cache="true" contentType="application/vnd.ms-excel#test.xls" controller="StoreController" language="english">

 

But what I need to do is display the VF page with the panelGrid.  Then the user can click a button or link that will export the grid to excel.

 

I was thinking of just creating a second visualforce page that contains the above apex:page line, but I don't know how to add that logic to a button/link.

 

Thanks

 

Todd 

Best Answer chosen by Admin (Salesforce Developers) 
ToddKruseToddKruse

I think I figured this out.  I created a second VF page and then in my cls file, I added this method:

 

   public PageReference save() 

   {

        return page.FiscalReportToExcelPage;

    }

 

this then calls the new VF page with the apex:page information directing it to be exported to excel.  Works like a charm.

 

Todd 

All Answers

Sam.arjSam.arj

Yes you will need two Visualforce pages or you may put the button as a custom button on a standard layout that launches the page that exports to Excel.

 

 

ToddKruseToddKruse

I think I figured this out.  I created a second VF page and then in my cls file, I added this method:

 

   public PageReference save() 

   {

        return page.FiscalReportToExcelPage;

    }

 

this then calls the new VF page with the apex:page information directing it to be exported to excel.  Works like a charm.

 

Todd 

This was selected as the best answer
Apex Code DevelopmentApex Code Development

Hi folks,

 

My requirement is: I've developed some code with an Apex Controller and a Visualforce page.The Visualforce page contains 3 picklist fields and a "Show" button.Once all these 3 picklist values were selected and clicked on "Show" button then a table of data with 3 colomns will be displayed.Up to here everything is fine.


Then I should have an "Export" button which exports the entire table data into an Excel.

 

I would be very thankful to you if you explain the idea of second VF page in Detail.

 

 

   Jagadeesh K.

s-Forces-Force

 

Hello Everyone,
Iam facing some problem in export to excel. i.e. my report is successfully exporting into the excel but in that excel sheet am getting the Calender and picklist fields. I don't knw how to remove all that. am attaching the excel sheet that am geeting. if anyone having idea regarding the same. Please reply ASAP.
Thanks In Advance.

 

 

vnvvnv

Hi,

 

I think you have used form tag in ur visualforce page, please remove the form tag and export u will not get calender values.

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.