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.
How to Add Freeze Pane to Spreadsheet
To add a freeze pane to your spreadsheet, follow these steps:

- Install the C# library required for freeze pane
- Use the
CreateFreezePane
with 2 parameters to add freeze pane - Use the
CreateFreezePane
with 4 parameters to add freeze pane as well as perform a pre-scrolled action on the spreadsheet - Export the spreadsheet to the desired file formats
Get started with IronXL
Start using IronXL in your project today with a free trial.
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;
// Load an existing Excel workbook named "sample.xlsx"
WorkBook workBook = WorkBook.Load("sample.xlsx");
// Get the first worksheet from the loaded workbook
WorkSheet workSheet = workBook.WorkSheets.First();
// Create a freeze pane in the worksheet.
// This will freeze the columns from A to B (2 columns) and rows from 1 to 3 (3 rows).
// Parameters (2, 3) indicate that columns A to B and rows 1 to 3 will be frozen.
workSheet.CreateFreezePane(2, 3);
// Save the modifications to a new file named "createFreezePanes.xlsx"
workBook.SaveAs("createFreezePanes.xlsx");
Imports IronXL
Imports System.Linq
' Load an existing Excel workbook named "sample.xlsx"
Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
' Get the first worksheet from the loaded workbook
Private workSheet As WorkSheet = workBook.WorkSheets.First()
' Create a freeze pane in the worksheet.
' This will freeze the columns from A to B (2 columns) and rows from 1 to 3 (3 rows).
' Parameters (2, 3) indicate that columns A to B and rows 1 to 3 will be frozen.
workSheet.CreateFreezePane(2, 3)
' Save the modifications to a new file named "createFreezePanes.xlsx"
workBook.SaveAs("createFreezePanes.xlsx")
Demonstration

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
// The following code is intended to remove any freeze or split panes in an Excel worksheet.
// Ensure you are using an appropriate library like EPPlus or NPOI that allows for worksheet manipulation.
// Note: This example assumes you are using the EPPlus library for Excel manipulation.
// Make sure to install the EPPlus NuGet package if it's not already installed.
// Remove all existing freeze or split panes in the worksheet
// Typically, the worksheet variable should be an instance of an Excel worksheet object.
// Ensure that 'worksheet' is initialized and appropriately refers to the worksheet you wish to modify.
// Example: var worksheet = package.Workbook.Worksheets["Sheet1"];
if (worksheet != null) // Ensure that the worksheet object is not null
{
worksheet.View.FreezePanes(1, 1); // This method removes any freeze panes applied to the worksheet
worksheet.View.SplitPanes(null); // Set this method to null to remove any existing split panes
// Note: If your library has different methods for adjusting panes, refer to its documentation.
}
else
{
Console.WriteLine("The worksheet object is null. Please ensure it is initialized correctly.");
}
// Explanation:
// - `FreezePanes(1, 1)` typically resets the freeze panes applied to the worksheet, if these methods are available in the library you use.
// - `SplitPanes(null)` is assumed behavior for removing split panes; actual methods may differ based on library.
// Always consult the documentation of the library you're using to confirm these methods.
' The following code is intended to remove any freeze or split panes in an Excel worksheet.
' Ensure you are using an appropriate library like EPPlus or NPOI that allows for worksheet manipulation.
' Note: This example assumes you are using the EPPlus library for Excel manipulation.
' Make sure to install the EPPlus NuGet package if it's not already installed.
' Remove all existing freeze or split panes in the worksheet
' Typically, the worksheet variable should be an instance of an Excel worksheet object.
' Ensure that 'worksheet' is initialized and appropriately refers to the worksheet you wish to modify.
' Example: var worksheet = package.Workbook.Worksheets["Sheet1"];
If worksheet IsNot Nothing Then ' Ensure that the worksheet object is not null
worksheet.View.FreezePanes(1, 1) ' This method removes any freeze panes applied to the worksheet
worksheet.View.SplitPanes(Nothing) ' Set this method to null to remove any existing split panes
' Note: If your library has different methods for adjusting panes, refer to its documentation.
Else
Console.WriteLine("The worksheet object is null. Please ensure it is initialized correctly.")
End If
' Explanation:
' - `FreezePanes(1, 1)` typically resets the freeze panes applied to the worksheet, if these methods are available in the library you use.
' - `SplitPanes(null)` is assumed behavior for removing split panes; actual methods may differ based on library.
' Always consult the documentation of the library you're using to confirm these methods.
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;
// Load the Excel workbook from a specified file
WorkBook workBook = WorkBook.Load("sample.xlsx");
// Get the first worksheet from the workbook
WorkSheet workSheet = workBook.WorkSheets.First();
// Create a freeze pane starting from column E (5th column) and row 5 (5th row).
// The scrolling will begin from column E (5th column) and row 5 (5th row),
// effectively freezing rows above and columns to the left of this cell.
workSheet.CreateFreezePane(5, 5, 6, 7);
// Save the modified workbook to a new file
workBook.SaveAs("createFreezePanes.xlsx");
Imports IronXL
Imports System.Linq
' Load the Excel workbook from a specified file
Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
' Get the first worksheet from the workbook
Private workSheet As WorkSheet = workBook.WorkSheets.First()
' Create a freeze pane starting from column E (5th column) and row 5 (5th row).
' The scrolling will begin from column E (5th column) and row 5 (5th row),
' effectively freezing rows above and columns to the left of this cell.
workSheet.CreateFreezePane(5, 5, 6, 7)
' Save the modified workbook to a new file
workBook.SaveAs("createFreezePanes.xlsx")
Demonstration

Please note
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 using IronXL?
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 with IronXL?
To add freeze panes using IronXL, 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 in IronXL?
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.