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.
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
Install with NuGet
Install-Package IronXL.Excel
Download DLL
Manually install into your project
Install with NuGet
Install-Package IronXL.Excel
Download DLL
Manually install into your project
Start using IronPDF in your project today with a free trial.
Check out IronXL on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming Excel with C#.
Install-Package IronXL.Excel
Consider installing the IronXL DLL directly. Download and manually install it for your project or GAC form: IronXL.zip
Manually install into your project
Download DLLAdd 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 row(1-4).
The code example below demonstrates how to create a freeze pane starting from columns A to B and rows 1 to 3:
: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")
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
// Remove all existing freeze or split pane
workSheet.RemovePane();
' Remove all existing freeze or split pane
workSheet.RemovePane()
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 freeze pane based on the specified column and row, as demonstrated in the example section. 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-...
Please note
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;
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")