+ Start a Discussion

Excel Export with Filtering


Is it possible to export to Excel with the filtering option turned on?  (Under Excel's 'Data' tab)

Presently, I have taken over manually exporting, leaving only the page intact (SF exports a page as HTML markup, and the data is exported as a table)

Here's an example of the Apex code:

public String exportGrid {
            String result = '<table><tr>'
            if( contactsExport == null )
                return '';
            for( Integer i = 0; i < contactsExport.size(); i++ )
                result +='<tr>';
                if( contactsExport[i].name != null )    
                result +='<td><span>'+contactsExport[i].name+'</span></td>';
                    result +='<td><span>&nbsp;</span></td>';
       return result + '</table>';


Here's what the VF page look like:

<apex:page controller="ContactSearchController" apiVersion="26.0" contenttype="application/vnd.ms-excel#Search.xls" showChat="false" showHeader="false" standardStylesheets="false" sidebar="false" cache="true">
  <apex:pageBlock title="Contacts">
      <apex:outputText rendered="{!resultsAreLimited}"><b>These Results Were Limited to 4,000 Records</b></apex:outputText>
    <apex:outputText escape="false">{!exportGrid}</apex:outputText>


Any help is appreciated.

Shivanath DevnarayananShivanath Devnarayanan

Hello Michael,

As far as i know you cannot manipulate how the excel gets exported.
but another option is for you to
1) create your separate VF page
2) you pass all the variables you require to render the data as query string params
3) Generate the VF and once you're satisfied
4) Change the content type of the new VF to pplication/vnd.ms-excel#Search.xls

I've also made a blog post : http://goo.gl/a8USZ

Hope this helps