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
Michael DsozaMichael Dsoza 

On button click, generate an excel sheet visualforce page

Hi All,

Requirement - On click on "Generate Excel" button, export pageBlockTable data into excel.
Solution Used - Created 2 VF Page, On button click of 1st VF page, redirecting it to 2nd VF page (page contentType="application/vnd.ms-excel#ExportToExcel.xls" cache="true") which is downloding as excel sheet. 
Problem - Excel sheet downloads correctly as expected but 1st VF page gets disabled and I have to hit the URL again to work it properly.

Please help me to resolve it.
Pankaj_GanwaniPankaj_Ganwani
Hi,

Use onclick javascript function for opening the page in new tab:
function redirect()
{
   window.open('/apex/pagename','_target');
}

In this way, the page open in new tab and 1st page will remain intact.
Michael DsozaMichael Dsoza
Hello Pankaj,
Thanks for your support.
I am able to open excel sheet in new tab but new tab remains open and manually i have to close it. So can you please tell me how to close the tab immediately after excel sheet downloads completes.

Thanks 
Pankaj_GanwaniPankaj_Ganwani
Hi,

Please simply use window.open(url); Remove _target from there. I think it should work.
Kt YadavKt Yadav
Requirement -Creat an excel using Apex and Visualforce Page.
Solution - Steps mentioned in the given link. http://wp.me/p98HXm-G