Use action function for that. From your commad button, call class's method and set the pageReference to Your excel page and then on the command button, use reRender attribute.
@Bhawani - if you use rerender then the pagereference will be ignored - rerender regenerates part of the existing page, it doesn't allow you to pull in parts of another page on the fly.
You can't avoid the blank page I'm afraid. The blank page is only skipped if you are linking directly to a .xls file, but you aren't - you are linking to a page that generates excel data. If you have a Visualforce page that renders as Excel, you need to open that page in the browser in order to create the Excel format information to download.
The best solution I've been able to come up with is to iframe the Visualforce page that generates the Excel format data inside another Visualforce page that contains some information about what is happening and a link to go back to the original page. Its not ideal but is a better experience than a blank page.
Thanks @Bob. I just reread and I was partially incorrect. But the only incorrect piece was reRender. otherwise approach will same.
Hi Manish,
Wriet a method in your class to rirect to the excel fiel. Will be similar to this:
public pageReference downloadExcelOfRecords() {
//Page Url set
PageReference newPage = New PageReference('/apex/SendExcelFileMonthly');
//Reinitiallize all the atribute by this
newPage.setRedirect(false);
//Return to page
return newPage;
}
result will be like this. This screenshot is from a running project and all is using VF page. On clicking Export details, it start downloading the Excel file. Parent screen is VF page.
You can't avoid the blank page I'm afraid. The blank page is only skipped if you are linking directly to a .xls file, but you aren't - you are linking to a page that generates excel data. If you have a Visualforce page that renders as Excel, you need to open that page in the browser in order to create the Excel format information to download.
The best solution I've been able to come up with is to iframe the Visualforce page that generates the Excel format data inside another Visualforce page that contains some information about what is happening and a link to go back to the original page. Its not ideal but is a better experience than a blank page.
Hi Manish,
Wriet a method in your class to rirect to the excel fiel. Will be similar to this:
From page, Call this method like:
result will be like this. This screenshot is from a running project and all is using VF page. On clicking Export details, it start downloading the Excel file. Parent screen is VF page.
Did it work for you?