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
manishtiwary1.390210540410199E12manishtiwary1.390210540410199E12 

Export salesforce Visual force page into PDF and Excel

I have a visualforce page in that i have created two button
1) Export Excel
2)Export Pdf

I have written code for for bothexport page in excel and PDF using rerender and contettype.
Also i have added custom button on my visulforce page.
<apex:commandButton action="{!URLFOR($Action.Five_c.Generate, Id)}" id="pdf" value="pdf"/>
<apex:commandButton action="{!URLFOR($Action.Five_c.excel, Id)}" id="excel" value="excel"/>
Now the problem is once I click on pdf button it redirect to the pdf page .What my requirnment is that pdf should open in new window i.e child page and parent page should also visible to us.

Similary for Excel it should happen
bob_buzzardbob_buzzard
If you make these commandlinks rather than commandbuttons, you can specify where the page should be opened. You can specify an inline style to make the link look like a button too : 

<apex:commandLink style="btn" action="{!URLFOR($Action.Five_c.Generate, Id)}" id="pdf" value="pdf" target="_blank" />
<apex:commandLink style="btn" action="{!URLFOR($Action.Five_c.excel, Id)}" id="excel" value="excel" target="_blank"/>


manishtiwary1.390210540410199E12manishtiwary1.390210540410199E12
Hi Thank you for the quick response. Now insted of using taget_blank. Is it possible to download excel and my view should be parent page only
bob_buzzardbob_buzzard
No, you can only do that if your link points directly to an excel/pdf file.  You are pointing to a Visualforce page that renders as the appropriate file type, so this needs to be opened in the browser.
manishtiwary1.390210540410199E12manishtiwary1.390210540410199E12
Problem is when I am clicking on excel expot.I am able to export in excel.But after export I am getting balnk sheet Insted of blank sheet it should redirect to the main(Parent Page)
bob_buzzardbob_buzzard
That's what happens I'm afraid.  I've worked around this in the past by embedding the Excel/PDF page inside an iframe on another page which has some text and a close button etc.
karthikeya 2karthikeya 2
Hi manishtiwary,

i am trying the same but i did not get the code can u send the vf page and controller page please my mail id is kvrit9@gmail.com
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.