A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: libraries/StructuredData.php

Line Number: 820

Backtrace:

File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 820
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1520
Function: buildHowToSchema

File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 2701
Function: buildBlogPostSchema

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 354
Function: setJsonLDStructuredData

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

Lock Excel Headers in VB.NET | Freeze Panes Tutorial Skip to footer content
USING IRONXL

VB.NET Excel Freeze Top Row: Keep Headers Visible While Scrolling

When working with large Excel documents containing hundreds of rows, keeping your header row visible while scrolling through data can be a challenge. The VB.NET Excel freeze top row functionality solves this issue by locking specific rows and columns in place. This article demonstrates how to use IronXL to create freeze panes programmatically in your .NET applications, helping users navigate spreadsheet data with speed and ease.

IronXL is a .NET library that lets you read, write, and manipulate Excel files without requiring Microsoft Office to be installed on the server. The CreateFreezePane method on the WorkSheet object is all you need to lock rows and columns in any Excel file your application produces or modifies.

Get started with a free trial to follow along with the code examples below.

How Do You Install IronXL for Your .NET Project?

Before writing any freeze pane code, add IronXL to your project using the NuGet Package Manager. Open your terminal and run:

dotnet add package IronXL.Excel
dotnet add package IronXL.Excel
SHELL

Alternatively, use the Visual Studio Package Manager Console:

Install-Package IronXL.Excel
Install-Package IronXL.Excel
SHELL

After installation, add the IronXL namespace at the top of your file. IronXL targets .NET 10 and supports all major platforms -- Windows, Linux, and macOS -- so your freeze pane logic runs the same way regardless of where you deploy.

Once installed, you can load existing workbooks or create new ones in just a few lines. The library works with both .xlsx (Excel 2007 and later) and .xls (Excel 97-2003) formats, though freeze pane support requires the modern .xlsx format. The table below summarizes the key WorkSheet methods covered in this guide.

IronXL Freeze Pane Methods
Method Parameters Description
CreateFreezePane(col, row) int col, int row Freezes the specified number of columns and rows from the top-left corner.
CreateFreezePane(col, row, leftmostCol, topRow) int col, int row, int leftmostCol, int topRow Freezes columns and rows with a pre-scrolled starting position for the scrolling pane.
RemovePane() none Removes any existing freeze or split panes from the worksheet.

How Do You Freeze Rows in an Excel File?

The answer is straightforward: use the CreateFreezePane method on your worksheet object. This method accepts parameters that control which rows and columns remain visible while the rest of the Excel sheet scrolls freely. When you freeze the first row, your header stays locked at the top no matter how far down you scroll through the data, similar to Excel's native Freeze Panes feature.

The following code snippet shows how to load an existing Excel document and freeze the top row:

using IronXL;
using System.Linq;

// Load an existing workbook from file
WorkBook workBook = WorkBook.Load("financial_report.xlsx");
WorkSheet workSheet = workBook.WorkSheets.First();

// Freeze the first row to keep headers visible
workSheet.CreateFreezePane(0, 1);

// Save the Excel file with freeze panes applied
workBook.SaveAs("financial_report_Frozen.xlsx");
using IronXL;
using System.Linq;

// Load an existing workbook from file
WorkBook workBook = WorkBook.Load("financial_report.xlsx");
WorkSheet workSheet = workBook.WorkSheets.First();

// Freeze the first row to keep headers visible
workSheet.CreateFreezePane(0, 1);

// Save the Excel file with freeze panes applied
workBook.SaveAs("financial_report_Frozen.xlsx");
Imports IronXL
Imports System.Linq

' Load an existing workbook from file
Dim workBook As WorkBook = WorkBook.Load("financial_report.xlsx")
Dim workSheet As WorkSheet = workBook.WorkSheets.First()

' Freeze the first row to keep headers visible
workSheet.CreateFreezePane(0, 1)

' Save the Excel file with freeze panes applied
workBook.SaveAs("financial_report_Frozen.xlsx")
$vbLabelText   $csharpLabel

Output

VB .NET Excel Freeze Top Row: Keep Headers Visible While Scrolling: Image 1 - Excel file with frozen first row

The CreateFreezePane(0, 1) method call freezes zero columns and one row. This keeps the top row visible while allowing all columns to scroll left and right. The parameters set which rows and columns exist above and to the left of the scrolling area. Thanks to this simple approach, users can check their data against header labels without losing their place in large documents.

The method uses zero-based counting for columns and one-based counting for rows, which matches the internal Excel file format. Passing 0 for the column parameter means no columns are frozen -- only the row you specify gets locked.

How Do You Freeze the First Column in Excel?

To freeze the first column instead of rows, adjust the parameters in the CreateFreezePane method. This is helpful when your Excel spreadsheet contains identifier information in column A that you want to keep visible while scrolling through additional columns to the right.

The following code snippet demonstrates how to create a new workbook and freeze the first column:

using IronXL;

// Create a new workbook and worksheet
WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.CreateWorkSheet("SalesData");

// Add sample header and data to the range
workSheet["A1"].Value = "Product ID";
workSheet["B1"].Value = "Q1 Sales";
workSheet["C1"].Value = "Q2 Sales";
workSheet["D1"].Value = "Q3 Sales";
workSheet["E1"].Value = "Q4 Sales";

// Populate a few rows of sample data
workSheet["A2"].Value = "PROD-001";
workSheet["B2"].Value = 14500;
workSheet["A3"].Value = "PROD-002";
workSheet["B3"].Value = 21300;

// Freeze the first column to keep Product IDs visible
workSheet.CreateFreezePane(1, 0);

// Save as xlsx file
workBook.SaveAs("SalesReport.xlsx");
using IronXL;

// Create a new workbook and worksheet
WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.CreateWorkSheet("SalesData");

// Add sample header and data to the range
workSheet["A1"].Value = "Product ID";
workSheet["B1"].Value = "Q1 Sales";
workSheet["C1"].Value = "Q2 Sales";
workSheet["D1"].Value = "Q3 Sales";
workSheet["E1"].Value = "Q4 Sales";

// Populate a few rows of sample data
workSheet["A2"].Value = "PROD-001";
workSheet["B2"].Value = 14500;
workSheet["A3"].Value = "PROD-002";
workSheet["B3"].Value = 21300;

// Freeze the first column to keep Product IDs visible
workSheet.CreateFreezePane(1, 0);

// Save as xlsx file
workBook.SaveAs("SalesReport.xlsx");
Imports IronXL

' Create a new workbook and worksheet
Dim workBook As WorkBook = WorkBook.Create()
Dim workSheet As WorkSheet = workBook.CreateWorkSheet("SalesData")

' Add sample header and data to the range
workSheet("A1").Value = "Product ID"
workSheet("B1").Value = "Q1 Sales"
workSheet("C1").Value = "Q2 Sales"
workSheet("D1").Value = "Q3 Sales"
workSheet("E1").Value = "Q4 Sales"

' Populate a few rows of sample data
workSheet("A2").Value = "PROD-001"
workSheet("B2").Value = 14500
workSheet("A3").Value = "PROD-002"
workSheet("B3").Value = 21300

' Freeze the first column to keep Product IDs visible
workSheet.CreateFreezePane(1, 0)

' Save as xlsx file
workBook.SaveAs("SalesReport.xlsx")
$vbLabelText   $csharpLabel

Output

VB .NET Excel Freeze Top Row: Keep Headers Visible While Scrolling: Image 2 - Excel file with frozen first column

Here, CreateFreezePane(1, 0) freezes one column and zero rows. The first column remains locked on the left side of the page while users scroll horizontally to read additional cell data. This is particularly useful for financial reports or inventory lists where product codes must stay visible as you move through quarterly breakdowns or attribute columns.

You can extend this pattern to freeze multiple columns. For example, passing 2 as the first argument locks the two leftmost columns in place, giving users a wider anchor as they navigate wide spreadsheets. This technique works well alongside cell range selection when you need to present data comparisons.

How Do You Freeze Both Rows and Columns Together?

For applications handling complex Excel documents, you may need to freeze panes that lock both the top row and the first column simultaneously. This keeps your header labels and row identifiers visible no matter which direction you scroll, making it easier to understand and filter through your cell data.

using IronXL;

// Load workbook or create a new one
WorkBook workBook = WorkBook.Load("Inventory.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Freeze first row AND first column simultaneously
workSheet.CreateFreezePane(1, 1);

// Save the document
workBook.SaveAs("Inventory_Frozen.xlsx");
using IronXL;

// Load workbook or create a new one
WorkBook workBook = WorkBook.Load("Inventory.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Freeze first row AND first column simultaneously
workSheet.CreateFreezePane(1, 1);

// Save the document
workBook.SaveAs("Inventory_Frozen.xlsx");
Imports IronXL

' Load workbook or create a new one
Dim workBook As WorkBook = WorkBook.Load("Inventory.xlsx")
Dim workSheet As WorkSheet = workBook.DefaultWorkSheet

' Freeze first row AND first column simultaneously
workSheet.CreateFreezePane(1, 1)

' Save the document
workBook.SaveAs("Inventory_Frozen.xlsx")
$vbLabelText   $csharpLabel

Output

VB .NET Excel Freeze Top Row: Keep Headers Visible While Scrolling: Image 3 - Output Excel file with the first row and column frozen

The CreateFreezePane(1, 1) call sets the freeze panes to lock one column and one row. When you open this file in Excel, scrolling in any direction keeps the header row and ID column visible on the page. This answers a common question developers have when building reporting applications that display tabular data across many rows and columns.

This configuration is common in inventory management, HR reporting, and financial dashboards where both vertical and horizontal navigation are routine. You can combine this with cell formatting -- bold headers, background colors -- so the frozen area stands out visually from the scrolling region.

How Do You Use the Advanced Freeze Panes Method with Pre-Scrolling?

IronXL provides an advanced option using four parameters that lets you add freeze panes with a pre-scrolled starting position. This controls not only what rows and columns are frozen but also where the scrolling area begins when users first open the file.

This is useful for dashboards or executive reports where you want the initial view to land on a specific data section -- for example, showing this month's data immediately while keeping the frozen header row and ID column visible.

using IronXL;
using System.Linq;

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

// Freeze columns A-B and rows 1-3
// Pre-scroll so the scrolling pane starts at row 8
workSheet.CreateFreezePane(2, 3, 2, 7);

workBook.SaveAs("LargeDataset_Configured.xlsx");
using IronXL;
using System.Linq;

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

// Freeze columns A-B and rows 1-3
// Pre-scroll so the scrolling pane starts at row 8
workSheet.CreateFreezePane(2, 3, 2, 7);

workBook.SaveAs("LargeDataset_Configured.xlsx");
Imports IronXL
Imports System.Linq

Dim workBook As WorkBook = WorkBook.Load("LargeDataset.xlsx")
Dim workSheet As WorkSheet = workBook.WorkSheets.First()

' Freeze columns A-B and rows 1-3
' Pre-scroll so the scrolling pane starts at row 8
workSheet.CreateFreezePane(2, 3, 2, 7)

workBook.SaveAs("LargeDataset_Configured.xlsx")
$vbLabelText   $csharpLabel

Output

VB .NET Excel Freeze Top Row: Keep Headers Visible While Scrolling: Image 4 - Advanced output Excel file

The additional parameters control where the split view begins. In this example, when the workbook opens, rows 1-3 remain frozen at the top while the scrolling section begins at row 8. The third parameter (leftmostCol) sets which column the right-hand scrolling pane starts from, and the fourth parameter (topRow) sets the first row visible in the lower scrolling pane.

Note that only one freeze pane configuration can exist per worksheet -- any subsequent call overwrites the previous setting. If you need to change the freeze configuration dynamically, call RemovePane() first, then call CreateFreezePane with the new parameters.

How Do You Remove Freeze Panes from a Worksheet?

If freeze panes already exist and you need to remove them, the RemovePane method handles this cleanly. This is helpful when you need to install a different freeze configuration or return the sheet to normal scrolling.

// Remove all existing freeze or split panes
workSheet.RemovePane();
// Remove all existing freeze or split panes
workSheet.RemovePane();
$vbLabelText   $csharpLabel

This single line clears any freeze panes that exist on the worksheet, allowing you to create fresh formatting or leave the document without frozen sections. After calling RemovePane, you can immediately call CreateFreezePane again with new parameters -- the two operations chain together naturally.

Note that freeze panes do not work with the Microsoft Excel 97-2003 (.xls) format due to file format limitations. For best results, save your documents as .xlsx files. If you encounter an issue with downloaded files not displaying freeze panes correctly, verify you are using a compatible Excel version and that the file is saved in the modern format.

You can also pair freeze pane removal with other worksheet operations. For example, before exporting a report to a different layout, you might remove the freeze configuration, add new rows and columns, restructure the data, and then apply a new freeze configuration that matches the updated layout.

How Do You Apply Freeze Panes Across Multiple Worksheets?

Many Excel workbooks contain several worksheets -- one per department, region, or time period. Applying freeze panes to each sheet programmatically saves time compared to doing it manually in the Excel application.

The following example loads a workbook, iterates over all worksheets, and applies the same freeze configuration to each one:

using IronXL;

WorkBook workBook = WorkBook.Load("MultiSheetReport.xlsx");

// Apply freeze panes to every worksheet in the workbook
foreach (WorkSheet sheet in workBook.WorkSheets)
{
    // Freeze top row and first column on each sheet
    sheet.CreateFreezePane(1, 1);
}

workBook.SaveAs("MultiSheetReport_Frozen.xlsx");
using IronXL;

WorkBook workBook = WorkBook.Load("MultiSheetReport.xlsx");

// Apply freeze panes to every worksheet in the workbook
foreach (WorkSheet sheet in workBook.WorkSheets)
{
    // Freeze top row and first column on each sheet
    sheet.CreateFreezePane(1, 1);
}

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

Dim workBook As WorkBook = WorkBook.Load("MultiSheetReport.xlsx")

' Apply freeze panes to every worksheet in the workbook
For Each sheet As WorkSheet In workBook.WorkSheets
    ' Freeze top row and first column on each sheet
    sheet.CreateFreezePane(1, 1)
Next

workBook.SaveAs("MultiSheetReport_Frozen.xlsx")
$vbLabelText   $csharpLabel

This pattern is especially practical for quarterly financial packs, where each sheet represents a month, or for multi-region sales reports where each region gets its own tab. Combined with sorting Excel range data and applying conditional formatting, you can build fully formatted, ready-to-share workbooks entirely from code.

IronXL also gives you access to the WorkBook object model for deeper workbook inspection. You can check the sheet count, retrieve sheets by name or index, and apply different freeze configurations to different sheets based on their content type -- for example, a summary sheet might freeze only the top row, while detail sheets freeze both a row and a column.

How Do You Validate Freeze Pane Settings Before Saving?

In production code it is good practice to verify the freeze pane configuration before writing the file to disk. IronXL does not currently expose a read-back API for freeze pane state directly, so the recommended approach is to track the configuration in your own code and assert that the save operation completes without error.

Here is a defensive coding pattern you can apply in any .NET 10 project:

using IronXL;
using System;

try
{
    WorkBook workBook = WorkBook.Load("source.xlsx");
    WorkSheet workSheet = workBook.DefaultWorkSheet;

    int freezeCol = 1;
    int freezeRow = 1;

    if (freezeCol >= 0 && freezeRow >= 0)
    {
        workSheet.CreateFreezePane(freezeCol, freezeRow);
        Console.WriteLine($"Freeze pane set: {freezeCol} column(s), {freezeRow} row(s).");
    }
    else
    {
        Console.WriteLine("Invalid freeze pane parameters -- skipping.");
    }

    workBook.SaveAs("output.xlsx");
    Console.WriteLine("Workbook saved successfully.");
}
catch (Exception ex)
{
    Console.WriteLine($"Error applying freeze pane: {ex.Message}");
}
using IronXL;
using System;

try
{
    WorkBook workBook = WorkBook.Load("source.xlsx");
    WorkSheet workSheet = workBook.DefaultWorkSheet;

    int freezeCol = 1;
    int freezeRow = 1;

    if (freezeCol >= 0 && freezeRow >= 0)
    {
        workSheet.CreateFreezePane(freezeCol, freezeRow);
        Console.WriteLine($"Freeze pane set: {freezeCol} column(s), {freezeRow} row(s).");
    }
    else
    {
        Console.WriteLine("Invalid freeze pane parameters -- skipping.");
    }

    workBook.SaveAs("output.xlsx");
    Console.WriteLine("Workbook saved successfully.");
}
catch (Exception ex)
{
    Console.WriteLine($"Error applying freeze pane: {ex.Message}");
}
Imports IronXL
Imports System

Try
    Dim workBook As WorkBook = WorkBook.Load("source.xlsx")
    Dim workSheet As WorkSheet = workBook.DefaultWorkSheet

    Dim freezeCol As Integer = 1
    Dim freezeRow As Integer = 1

    If freezeCol >= 0 AndAlso freezeRow >= 0 Then
        workSheet.CreateFreezePane(freezeCol, freezeRow)
        Console.WriteLine($"Freeze pane set: {freezeCol} column(s), {freezeRow} row(s).")
    Else
        Console.WriteLine("Invalid freeze pane parameters -- skipping.")
    End If

    workBook.SaveAs("output.xlsx")
    Console.WriteLine("Workbook saved successfully.")
Catch ex As Exception
    Console.WriteLine($"Error applying freeze pane: {ex.Message}")
End Try
$vbLabelText   $csharpLabel

This pattern validates parameters before calling the API and wraps the save operation in a try-catch block so any file system or format errors are caught cleanly. For server-side report generation, this kind of defensive code prevents silent failures in batch processing pipelines.

You can find more patterns for working with Excel worksheets and creating Excel charts in the IronXL documentation, which covers the full range of spreadsheet operations the library supports.

How Do You Combine Freeze Panes with Other IronXL Features?

Freeze panes become even more valuable when combined with other spreadsheet formatting and data operations. The most common combinations in real-world .NET applications include:

Header formatting with freeze panes. Freeze the top row and then apply bold formatting, background color, or border styles to the header cells so they stand out clearly from the data rows below. Users notice immediately that the frozen row is a header rather than a data row.

Auto-fit column widths. After populating data, auto-fit column widths so each column is exactly wide enough for its content. This eliminates truncated text and makes the frozen header labels readable at a glance.

Data validation and cell protection. Combine freeze panes with cell protection to lock header cells against accidental editing. End users can scroll and interact with data while the protected header row remains frozen and read-only.

Sorting and filtering. Apply Excel AutoFilter to the header row before freezing it. When users open the file, they see filterable column headers pinned at the top -- a pattern familiar from native Excel applications.

According to Microsoft's Excel documentation, freeze panes are stored in the worksheet's sheetView XML element inside the OOXML package. IronXL writes this element correctly, so files produced by the library open in Excel, LibreOffice, and Google Sheets without additional configuration.

The Apache POI project -- the Java equivalent for Excel manipulation -- uses the same underlying OOXML specification, so the freeze pane behavior is consistent with what Java developers expect from their own tooling.

What Are Your Next Steps?

Implementing freeze panes is one of the most effective ways to improve the user experience of your .NET Excel reports. By locking headers and identifiers in place, you transform static data into an interactive reporting tool that users can navigate with confidence.

Here is a summary of what this guide covered:

  • Simple row freeze -- CreateFreezePane(0, 1) locks the top row for vertical scrolling.
  • Simple column freeze -- CreateFreezePane(1, 0) locks the leftmost column for horizontal scrolling.
  • Combined freeze -- CreateFreezePane(1, 1) locks both the top row and the first column.
  • Advanced pre-scroll -- CreateFreezePane(col, row, leftmostCol, topRow) sets a custom starting position for the scrolling pane.
  • Remove panes -- RemovePane() clears any existing freeze or split configuration.
  • Multi-sheet application -- Iterate over workBook.WorkSheets to apply the same freeze settings across an entire workbook.

To continue building on these skills, explore these related guides in the IronXL documentation:

For production use, purchase a license to unlock all features and deploy with confidence. The IronXL licensing page also covers deployment options, royalty-free redistribution, and SaaS use cases.

Get stated with IronXL now.
green arrow pointer

Frequently Asked Questions

How can I keep the header row visible in Excel using VB.NET?

You can keep the header row visible by using IronXL's CreateFreezePane method in your VB.NET application to lock the top row, ensuring it remains visible while scrolling through the data.

What is the purpose of freezing panes in Excel?

Freezing panes in Excel helps maintain visibility of certain rows or columns, such as headers, while navigating through large datasets, which enhances data analysis and usability.

Can IronXL be used to programmatically freeze panes in Excel?

Yes, IronXL allows you to programmatically freeze panes in Excel, enabling you to lock specific rows or columns in place using the CreateFreezePane method.

Is it possible to freeze both rows and columns at the same time using VB.NET?

Yes, using IronXL in VB.NET, you can freeze both rows and columns simultaneously by specifying the rows and columns you want to lock with the CreateFreezePane method.

What is IronXL's CreateFreezePane method?

IronXL's CreateFreezePane method is a feature that allows developers to lock specific rows and columns in Excel spreadsheets programmatically, enhancing data navigation and analysis.

Why should developers use IronXL for Excel operations in VB.NET?

Developers should use IronXL for Excel operations in VB.NET because it simplifies complex tasks like freezing panes, making it easier to manage large datasets and improve the user experience.

How does freezing panes improve the usability of Excel spreadsheets?

Freezing panes improves usability by keeping important data, such as headers, visible at all times, which aids in efficient data analysis and navigation through large spreadsheets.

Can IronXL handle large Excel files efficiently?

Yes, IronXL is designed to handle large Excel files efficiently, providing features like freeze panes to help manage and navigate extensive data without unnecessary overhead.

Is IronXL suitable for both beginners and advanced developers?

IronXL is suitable for both beginners and advanced developers due to its clear API and rich feature set, including the CreateFreezePane method for Excel operations in VB.NET.

What are the benefits of using IronXL for Excel automation tasks?

The benefits of using IronXL for Excel automation tasks include ease of use, the ability to programmatically manipulate spreadsheets, and enhanced features like freeze panes for better data management.

Jordi Bardia
Software Engineer
Jordi is most proficient in Python, C# and C++, when he isn’t leveraging his skills at Iron Software; he’s game programming. Sharing responsibilities for product testing, product development and research, Jordi adds immense value to continual product improvement. The varied experience keeps him challenged and engaged, and he ...
Read More

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me