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

Freeze header pane in excel while Importing

Hi Everyone,

I am trying to free header pane in excel, while am exporting it from Salesforce.

There is a method in Java


Is there anything using javascript or something else in Apex class or page so that we can freeze the header in excel.

Abhi Tripathi
Salesforce Certified Developer
Hi Abhi,

There is something similar in jquery which might of use to you :
worth a read!
Hi Sonam, 

thanks for the reply, but I have tried this on, not working, as salesforce made changes in the EXCEL file by itself. can't find exact place to modify my Excel on page.

Vaib ParaVaib Para
This is how it is done.

Hi, This is the code which has freeze panes. I found out a way to do that. Headers will be fixed when the visualforce page is downloaded as excel.

My next requirement is to have conditional coloring.?? Any idea on how to do that?

<apex:page controller="ExportToExcelMultipleSheets" contentType="application/" cache="true">

<apex:outputText value="{!xlsHeader}"/>
<Workbook  xmlns="urn:schemas-microsoft-com:office:spreadsheet"

 <Style ss:ID="s1">
 <Alignment ss:Vertical="Top"/>
<Font ss:Bold="1"/>
 <Interior ss:Color="#800080" ss:Pattern="Solid" />
 <Worksheet ss:Name="Contacts">
 <Table  x:FullColumns="1" x:FullRows="1">

 <Column  ss:Width="100" />
 <Column  ss:Width="100" />
 <Column  ss:Width="100"/>
 <Row ss:Height="25">
 <Cell ss:StyleID="s1"><Data ss:Type="String" >Contact Name</Data><NamedCell ss:Name="_FilterDatabase"/></Cell>
 <Cell ss:StyleID="s1"><Data ss:Type="String" >Email</Data><NamedCell ss:Name="_FilterDatabase"/></Cell>
 <Cell ss:StyleID="s1"><Data ss:Type="String" >Account Name</Data><NamedCell ss:Name="_FilterDatabase"/></Cell>
 <Cell ss:StyleID="s1"><Data ss:Type="String" >Birth Date</Data><NamedCell ss:Name="_FilterDatabase"/></Cell>
 <Cell  ss:StyleID="s1"><Data ss:Type="String" >Mobile</Data><NamedCell ss:Name="_FilterDatabase"/></Cell>
 <apex:repeat value="{!contactList}" var="contact">
 <Cell><Data ss:Type="String"><apex:outputText style="color:#000;" value="{!}"/></Data></Cell>
 <Cell><Data ss:Type="String">{!}</Data></Cell>
 <Cell><Data ss:Type="String">{!}</Data></Cell>
 <Cell><Data ss:Type="String"><apex:outputText value="{0,date,MM/dd/yy}" ><apex:param value="{!contact.Birthdate}" /></apex:outputText></Data></Cell>
 <Cell><Data ss:Type="String">{!contact.MobilePhone}</Data></Cell>
 <Row ss:StyleID="s1">
 <Cell><Data ss:Type="String">Planning</Data></Cell>
 <Cell><Data ss:Type="String">test</Data></Cell>
 <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">



public with sharing class ExportToExcelMultipleSheets {
public List<Account> accountList{get;set;}
public List<Contact> contactList{get;set;}
public String xlsHeader {
        get {
            String strHeader = '';
            strHeader += '<?xml version="1.0"?>';
            strHeader += '<?mso-application progid="Excel.Sheet"?>';
            return strHeader;
public ExportToExcelMultipleSheets(){
    accountList = [select id, name from Account LIMIT 50];
    contactList = [Select id, name,,MobilePhone,Birthdate, email from Contact LIMIT 50];
public Pagereference exportAll(){
    return new Pagereference('/apex/exportAll');