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 

How prevent to redirect to blank page on Excel Export

How we can prevent to redirect a visual force page to blank page on excel export
Bhawani SharmaBhawani Sharma
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 SharmaBhawani Sharma
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.
manishtiwary1.390210540410199E12manishtiwary1.390210540410199E12
Hi, Is there any Example code for the above. So that I can follow and implement the logic
bob_buzzardbob_buzzard
@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.
Bhawani SharmaBhawani Sharma
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;     
    }

From page, Call this method like:
<apex:commandButton value="Export Details" action="{!downloadExcelOfRecords}" style="width:100px;"/>
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.

User-added image





Bhawani SharmaBhawani Sharma
Hi Manish, 

Did it work for you?