How to Add Freeze Panes

Introduction

In large table of data sheet it become very difficult to view the data in 50+ rows or column passed 'Z' column at the same time with their corresponding Headers that stay either on the first row or column. Freeze Panes functionality will solve this issue in a clever way.

C# NuGet Library for Excel

Install with NuGet

Install-Package IronXL.Excel
or
C# Excel DLL

Download DLL

Download DLL

Manually install into your project

Add Freeze Panes Example

Freeze pane is the option to lock rows and columns in place, allowing them to remain visible while scrolling. It is a very useful feature to keep the header column or row in place while quickly compare information.

CreateFreezePane(int column, int row)

Add freeze pane from column(A) and row(1) up to, but NOT INCLUDING the specified column and row. For example, workSheet.CreateFreezePane(1, 4) will make freeze pane of column(A) and row(1-4).

The code example below shows how to create freeze pane from column(A-B) and row(1-3):

:path=/static-assets/excel/content-code-examples/how-to/add-freeze-panes-add.cs
using IronXL;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.WorkSheets.First();

// Create freeze pane from column(A-B) and row(1-3)
workSheet.CreateFreezePane(2, 3);

workBook.SaveAs("createFreezePanes.xlsx");
Imports IronXL

Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
Private workSheet As WorkSheet = workBook.WorkSheets.First()

' Create freeze pane from column(A-B) and row(1-3)
workSheet.CreateFreezePane(2, 3)

workBook.SaveAs("createFreezePanes.xlsx")
VB   C#

Demonstration

Freeze Panes in Action

Remove Freeze Panes

Freeze panes can be removed with just one line of code. Use RemovePane() method to remove all existing freeze panes.

:path=/static-assets/excel/content-code-examples/how-to/add-freeze-panes-remove.cs
// Remove all existing freeze or split pane
workSheet.RemovePane();
' Remove all existing freeze or split pane
workSheet.RemovePane()
VB   C#

Advanced

CreateFreezePane method has a more advance option to not only create freeze panes, but also apply scrolling.

CreateFreezePane(int column, int row, int subsequentColumn, int subsequentRow)

Add freeze pane based on the specified column and row like in the example section. In addition, apply scrolling to the worksheet.

For example, workSheet.CreateFreezePane(5, 2, 6, 7) will have freeze pane from column(A-E) and row(1-2) with 1 column and 5 row scroll. When the worksheet is first open it will show column A-E,G-... and the row will show 1-2,8-...

Please note

  • Only 1 setting of freeze pane can be applied. Any additional creation of freeze pane will overwrite the previous one.
  • Freeze pane does not work with Microsoft Excel versions 97-2003(.xls)
:path=/static-assets/excel/content-code-examples/how-to/add-freeze-panes-advance.cs
using IronXL;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.WorkSheets.First();

// Overwriting freeze or split pane to column(A-E) and row(1-5) as well as applying prescroll
// The column will show E,G,... and the row will show 5,8,...
workSheet.CreateFreezePane(5, 5, 6, 7);

workBook.SaveAs("createFreezePanes.xlsx");
Imports IronXL

Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
Private workSheet As WorkSheet = workBook.WorkSheets.First()

' Overwriting freeze or split pane to column(A-E) and row(1-5) as well as applying prescroll
' The column will show E,G,... and the row will show 5,8,...
workSheet.CreateFreezePane(5, 5, 6, 7)

workBook.SaveAs("createFreezePanes.xlsx")
VB   C#

Demonstration

Advance Freeze Panes Demonstration

If you have a large table of data in Excel, it can be useful to freeze rows or columns. This way you can keep rows or columns visible while scrolling through the rest of the worksheet.