+ Start a Discussion
PerdedorkPerdedork 

Excel Export with Filtering

Hi,

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 {
        get{
            String result = '<table><tr>'
                +'<td><b>Name</b></td><td><b>City</b></td><td><b>State</b></td>'
                +'<td><b>Zip</b></td><td><h>Country</h></td><td><b>E-Mail</b></td>'
                +'<td><b>Mobile</b></td><td><b>Home</b></td><td><b>Work</b></td>'
                +'</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>';
                else
                    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>
  </apex:pageBlock>
</apex:page>

 



Any help is appreciated.

Thanks,
Michael
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