IRONSOFTWAREHOME

How to Add Freeze Pane in Excel with C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

In large Excel spreadsheets with 50+ rows or columns beyond 'Z', viewing data while keeping headers visible becomes challenging. The Freeze Pane functionality in C# provides an elegant solution by locking specific rows and columns in place while allowing the rest to scroll freely.

This feature becomes essential when working with financial reports, employee databases, or inventory lists where you need constant visibility of column headers or row identifiers. With IronXL's Excel library, you can programmatically add freeze panes to improve data navigation and user experience in your .NET applications.

Quickstart: Lock Header Rows and Columns in One Line

Use the simple CreateFreezePane(colSplit, rowSplit) method to freeze rows or columns in seconds. No complex setup - just load your sheet, call this method, and your headers stay locked at the top while you scroll.

  1. 1Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. 2Copy and run this code snippet.

    workSheet.CreateFreezePane(1, 4);
    C#
  3. 3Deploy to test on your live environment

    Start using IronXL in your project today with a free trial
    arrow pointer

How Do I Add Freeze Pane in Excel?

Freeze panes lock rows and columns in place, allowing them to remain visible while scrolling. This feature keeps header columns or rows in place while quickly comparing information. This functionality is particularly valuable when working with large datasets or when you need to maintain context while navigating through extensive spreadsheets.

The freeze pane feature in IronXL mimics Excel's native functionality, making it intuitive for developers familiar with Excel's interface. Unlike Excel Interop solutions, IronXL provides a more efficient and server-friendly approach to implementing freeze panes programmatically.

How Does CreateFreezePane Work with 2 Parameters?

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) creates a freeze pane starting from column A and rows 1 to 4.

Understanding zero-based indexing is crucial: column 0 refers to column A, column 1 to B, and so on. Row indexing follows the same pattern. This method is perfect for scenarios where you want to keep headers visible while scrolling through data entries.

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

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");

What Does Freeze Pane Look Like in Action?

Freeze Pane in Action

How Do I Remove Freeze Pane?

Use the RemovePane method to remove all existing freeze panes from your spreadsheet. This is useful when you need to reset the view or apply different freeze settings based on user preferences or data changes.

// Remove all existing freeze or split pane
workSheet.RemovePane();

What Are the Advanced Freeze Pane Options?

The CreateFreezePane method offers an advanced option to create freeze panes with pre-scrolling functionality. This feature is useful when you want to focus attention on a specific area of the spreadsheet while maintaining the freeze pane functionality.

When Should I Use 4 Parameters for Advanced Freeze Panes?

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. This is especially beneficial when working with formatted Excel reports where you need precise control over the initial view.

For instance, using workSheet.CreateFreezePane(5, 2, 6, 7) creates a freeze pane that spans columns A-E and rows 1-2. It includes a 1-column and 5-row scroll. When the worksheet opens, it displays columns A-E, G-... and rows 1-2, 8-....

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");

What Does Advanced Freeze Pane Look Like?

Excel freeze panes demo showing employee data with frozen headers and ID column, blue arrow indicates freeze boundary

Practical Use Cases for Freeze Panes

Freeze panes are invaluable in various business scenarios:

  1. Financial Reports: Keep month/quarter headers visible while scrolling through yearly data
  2. Employee Databases: Lock employee names and IDs while viewing performance metrics
  3. Inventory Management: Fix product codes and names while reviewing stock levels
  4. Sales Dashboards: Maintain visibility of product categories while analyzing regional sales data

When combined with Excel formulas, freeze panes enhance data analysis efficiency significantly.

Complete Example: Building a Data Report with Freeze Panes

Here's a comprehensive example showing how to create a formatted report with freeze panes:

using IronXL;
using IronXL.Styles;

// Create a new workbook
WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.CreateWorkSheet("Sales Report");

// Add headers
workSheet["A1"].Value = "Product ID";
workSheet["B1"].Value = "Product Name";
workSheet["C1"].Value = "Q1 Sales";
workSheet["D1"].Value = "Q2 Sales";
workSheet["E1"].Value = "Q3 Sales";
workSheet["F1"].Value = "Q4 Sales";
workSheet["G1"].Value = "Total";

// Style headers
var headerRange = workSheet["A1:G1"];
headerRange.Style.Font.Bold = true;
headerRange.Style.BackgroundColor = "#4472C4";
headerRange.Style.Font.Color = "#FFFFFF";

// Add sample data
for (int i = 2; i <= 50; i++)
{
    workSheet[$"A{i}"].Value = $"P{i-1:D3}";
    workSheet[$"B{i}"].Value = $"Product {i-1}";
    workSheet[$"C{i}"].Value = Random.Shared.Next(1000, 5000);
    workSheet[$"D{i}"].Value = Random.Shared.Next(1000, 5000);
    workSheet[$"E{i}"].Value = Random.Shared.Next(1000, 5000);
    workSheet[$"F{i}"].Value = Random.Shared.Next(1000, 5000);
    workSheet[$"G{i}"].Formula = $"=SUM(C{i}:F{i})";
}

// Apply freeze pane to keep headers visible
workSheet.CreateFreezePane(0, 1);

// Auto-size columns for better visibility
for (int col = 0; col <= 6; col++)
{
    workSheet.AutoSizeColumn(col);
}

// Save the workbook
workBook.SaveAs("SalesReportWithFreezePanes.xlsx");
C#

This example demonstrates how freeze panes work with cell styling and formulas to create professional reports. The header row remains visible as users scroll through the 50 rows of sales data.

Performance Considerations

When implementing freeze panes in large spreadsheets:

  • Apply freeze panes after populating data for optimal performance
  • Consider using conditional formatting to highlight important data in frozen sections
  • Test with your target data volume to ensure smooth scrolling performance

For applications handling extensive datasets, explore exporting to different formats or implementing pagination strategies alongside freeze panes.

Please note: Only one freeze pane setting 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

How do I add freeze panes in Excel using C# with IronXL?

To add freeze panes in Excel using C# with IronXL, you can use the `CreateFreezePane(colSplit, rowSplit)` method. This allows you to lock specific rows and columns in place while the rest scrolls freely in your .NET applications.

Can I customize the starting row and column for freeze panes in IronXL?

Yes, IronXL allows you to specify the column and row from which the freeze pane should start using the `CreateFreezePane` method. This helps keep your headers visible while navigating through large datasets.

What are the practical applications of using freeze panes in Excel?

Freeze panes are particularly useful in financial reports, employee databases, and inventory management where you need to keep headers or identifier columns visible while scrolling through data.

How can I remove a freeze pane with IronXL?

To remove a freeze pane in IronXL, you can use the `RemovePane` method which clears all existing freeze or split panes from your spreadsheet.

Does IronXL support advanced freeze pane options?

Yes, IronXL offers advanced freeze pane options allowing for scrolling functionality and precise control over the initial view, making it suitable for formatted Excel reports.

Is it possible to implement freeze panes for large datasets with smooth performance?

IronXL is optimized for performance, even with large datasets. It is recommended to apply freeze panes after populating data and consider using pagination strategies to ensure smooth scrolling.

Can I programmatically set freeze panes to display specific data areas?

Yes, you can set freeze panes and use pre-scrolling functionality to focus on specific areas of your spreadsheet when it opens.

Are there any compatibility considerations when using freeze panes in IronXL?

IronXL's freeze pane functionality does not work with Microsoft Excel versions 97-2003 (.xls) and only one freeze pane setting can be applied at a time, which will overwrite the previous one.

What coding languages are compatible with IronXL for adding freeze panes?

IronXL is designed for use within C# .NET applications, allowing developers to integrate Excel functionalities programmatically in this environment.

How does IronXL differ from Excel Interop for adding freeze panes?

IronXL provides a more efficient, server-friendly approach to implementing freeze panes compared to Excel Interop solutions, making it ideal for high-performance applications.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 2,237,574Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronXL.Excel
nuget.org/packages/IronXL.Excel/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronXL"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronXL to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronXL.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required