4

How can I freeze top row (and only the row) using spreadsheetgear?

when I try this:

worksheet.WindowInfo.FreezePanes = true;

It freezes both the top row and the first column (A). I only need it to freeze the top row.

Zar Shardan
  • 5,675
  • 2
  • 39
  • 37

2 Answers2

3

After some research I found out I need to select the cell first and then set the FreezePanes property:

worksheet.Cells[1,0].Select();
worksheet.WindowInfo.FreezePanes = true;

Basically what happens is it freezes rows above and columns to the left of the selected cell.

Zar Shardan
  • 5,675
  • 2
  • 39
  • 37
  • 2
    You could also use IWorksheetWindowInfo.SplitRows/SplitColumns to specify where the "splits" should occur. In your case you would set SplitRows to 1. Then use IWorksheetWindowInfo.FreezePanes to "freeze" the split. – Tim Andersen Jun 06 '13 at 15:48
  • Interesting, It worked that way too. I thought I tried that, but probably that was ScrollRow or I didn't set the FreezePanes property when I tried it. I actually like your solution more. – Zar Shardan Jun 07 '13 at 02:36
1

The above solution did not work for me. Here's what I did and succeeded:

worksheet.WindowInfo.ScrollColumn = 0;
worksheet.WindowInfo.SplitColumns = 0;
worksheet.WindowInfo.ScrollRow = 0;
worksheet.WindowInfo.SplitRows = 1;
worksheet.WindowInfo.FreezePanes = true;
papps
  • 109
  • 1
  • 12