I\'m exporting an ASP.NET gridview to Excel using the following function. The formatting is working really well, except I need to freeze the header row in Excel on the expo
Modify the WorksheetOption element to something like the following:
<x:WorksheetOptions>
<x:Selected/>
<x:FreezePanes/>
<x:FrozenNoSplit/>
<x:SplitHorizontal>1</x:SplitHorizontal>
<x:TopRowBottomPane>1</x:TopRowBottomPane>
<x:ActivePane>2</x:ActivePane>
<x:Panes>
<x:Pane>
<x:Number>3</x:Number>
</x:Pane>
<x:Pane>
<x:Number>2</x:Number>
</x:Pane>
</x:Panes>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
Notice the FreezePanes element. I cut this out of a spreadsheet that I had saved as HTML with the first row frozen. When this file is opened with Excel, the first row is frozen.
EDIT: To have the header row print on each page, you will need something like this:
<x:ExcelName>
<x:Name>Print_Area</x:Name>
<x:SheetIndex>1</x:SheetIndex>
<x:Formula>=Sheet1!$A$2:$F$97</x:Formula>
</x:ExcelName>
<x:ExcelName>
<x:Name>Print_Titles</x:Name>
<x:SheetIndex>1</x:SheetIndex>
<x:Formula>=Sheet1!$1:$1</x:Formula>
</x:ExcelName>
You will need to modify the values in the formula dynamically for your data.
Perhaps you can use a trick that I employ when I am trying to do "specialty" formatting, etc...
Create an XLS with all the row and cell formats you'd like already expressed. Then COPY it, add your data, and SAVE it.
In this manner you do not need any payed-for plug-ins, and you ALWAYS get EXACTLY whatever formatting you want...
Need more than one specialty? Create another my_MT_Excel.xls with the needed formatting.
You could have a folder full of these things all ready to go without resorting to the more intricate programming techniques.
tob