I am creating an Excel spreadsheet in C#. I like to have the header (first) row pinned in place when the user scrolls the rows. How can I do this in C# (or VB.NET)?
+3
A:
I know that this not a fully detailed answer, but it should help you in the right direction. When I previously did a lot of Perl and later Ruby automation of Excel and wanted to know how to achieve this and that I usually recorded a macro and inspected its code to see how VBA interacted with the objects. I also did so for your task and this is what I got:
Sub Makro1()
'
' Makro1 Makro
'
'
ActiveWindow.SplitRow = 1.1
With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True
End Sub
I will leave it to somebody else to translate into C#, but it should be a walk in the park.
Christian Madsen
2010-01-15 19:21:35
That looks easier than I expected it to be.
RedFilter
2010-01-15 19:24:11
That's a simple, but neat trick. Nice answer :)
Scott Anderson
2010-01-15 19:26:59
This worked. Thanks.
Tony_Henrich
2010-01-15 19:53:07
A:
This should do it in C#.
Private freezePain ()
{
...initialize objects
ExcelObject.ActiveWindow.FreezePanes = false;
WorksheetObject.get_Range(yourRange).Select();
ExcelObject.ActiveWindow.FreezePanes = true;
}
Irwin M. Fletcher
2010-01-15 19:25:53
For some reason more rows and fewer columns are frozen even though I have my range correct.
Tony_Henrich
2010-01-15 19:52:01