How to Add Freeze Pane

Introduction

In a large data sheet table, it can be challenging to view the data in 50+ rows or columns beyond the 'Z' column while keeping the corresponding headers in view. The Freeze Pane functionality provides a clever solution to this issue.


Get started with IronXL

Start using IronXL in your project today with a free trial.

First Step:
green arrow pointer


Add Freeze Pane Example

Freeze panes is an option to lock rows and columns in place, allowing them to remain visible while scrolling. It is a very useful feature for keeping the header column or row in place while quickly comparing information.

CreateFreezePane(int column, int row)

To add a freeze pane, use the CreateFreezePane method, specifying the column and row from which the freeze pane should start. The specified column and row are not included in the freeze pane. For example, workSheet.CreateFreezePane(1, 4) will create a freeze pane starting from column A and rows 1 to 4.

The code example below demonstrates how to create a freeze pane starting from column B and row 4:

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

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
Imports System.Linq

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")
$vbLabelText   $csharpLabel

Demonstration

Freeze Pane in Action

Remove Freeze Pane

Use the RemovePane method to quickly remove all existing freeze panes from your spreadsheet.

: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()
$vbLabelText   $csharpLabel

Advanced Freeze Pane Example

The CreateFreezePane method offers an advanced option to create freeze panes with pre-scrolling functionality.

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

This method allows you to add a freeze pane based on the specified starting column and row. Additionally, it enables you to apply scrolling to the worksheet.

For instance, by using workSheet.CreateFreezePane(5, 2, 6, 7), you can create a freeze pane that spans columns A-E and rows 1-2. It includes a 1-column and 5-row scroll. When the worksheet is first opened, it will display columns A-E, G-... and rows 1-2, 8-...

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

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
Imports System.Linq

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")
$vbLabelText   $csharpLabel

Demonstration

Advanced Freeze Panes Demonstration

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).

Frequently Asked Questions

What is a freeze pane in Excel?

A freeze pane is a feature that allows you to lock rows and columns in place, enabling them to remain visible while you scroll through the rest of the spreadsheet.

How can I add a freeze pane to a spreadsheet?

You can add a freeze pane using the `CreateFreezePane` method in IronXL. Specify the starting column and row to create the freeze pane. For example, `workSheet.CreateFreezePane(1, 4)` will start the pane from column A and rows 1 to 4.

What are the prerequisites for adding freeze panes to a spreadsheet?

To add freeze panes, you need to install the IronXL Excel library from NuGet.

Can I add a freeze pane with scrolling functionality?

Yes, the `CreateFreezePane` method allows you to add a freeze pane with scrolling by specifying additional parameters for subsequent columns and rows.

How do I remove a freeze pane from a spreadsheet?

You can remove all existing freeze panes using the `RemovePane` method in IronXL.

Does Microsoft Excel support all freeze pane functionalities?

IronXL's freeze pane feature does not work with Microsoft Excel versions 97-2003 (.xls).

Can I apply multiple freeze pane settings in a single worksheet?

No, only one freeze pane setting can be applied at a time. Any new creation of a freeze pane will overwrite the previous one.

What file formats can I export to after adding freeze panes?

After adding freeze panes, you can export your spreadsheet to various file formats using IronXL.

Chaknith related to Demonstration
Software Engineer
Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.