Cómo crear un archivo de Excel en C#

How to Add Freeze Pane

This article was translated from English: Does it need improvement?
Translated
View the article in English

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.

Quickstart: Lock Header Rows and Columns in One Line

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

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. Copy and run this code snippet.

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

    Start using IronXL in your project today with a free trial
    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

Por favor notaOnly 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).

Preguntas Frecuentes

¿Cómo agrego un panel inmovilizado a una hoja de cálculo usando C#?

Para agregar un panel inmovilizado a una hoja de cálculo en C#, use el método CreateFreezePane de IronXL. Especifique la columna y fila de inicio, como workSheet.CreateFreezePane(1, 4), que bloquea las filas 1 a 4 y la columna A.

¿Cuál es el propósito de usar paneles inmovilizados en Excel?

Los paneles inmovilizados se utilizan para bloquear filas o columnas específicas en su lugar, permitiendo que permanezcan visibles mientras se desplaza por otras partes de la hoja de cálculo. Esto es particularmente útil para mantener visibles los encabezados o datos clave al navegar por conjuntos de datos grandes.

¿Cómo puedo eliminar los paneles inmovilizados de una hoja de cálculo automáticamente?

Para eliminar los paneles inmovilizados automáticamente usando IronXL, utilice el método RemovePane, que elimina todos los paneles inmovilizados existentes de la hoja de cálculo.

¿Se pueden aplicar paneles inmovilizados a formatos de archivo antiguos de Excel?

No, los paneles inmovilizados creados usando IronXL no funcionan con los formatos de archivo de Microsoft Excel de las versiones 97-2003 (.xls).

¿Es posible crear múltiples paneles inmovilizados en una sola hoja de trabajo?

No, solo se puede aplicar un panel inmovilizado a la vez en una hoja de trabajo. Cualquier nueva creación de panel inmovilizado sobrescribirá la anterior.

¿Cómo puedo crear un panel inmovilizado con funcionalidad de predisposición?

IronXL le permite crear un panel inmovilizado con predisposición utilizando el método CreateFreezePane con cuatro parámetros. Por ejemplo, workSheet.CreateFreezePane(5, 2, 6, 7) crea un panel inmovilizado que comienza desde las columnas A-E y las filas 1-2, con un desplazamiento que comienza desde la columna G y la fila 8 al abrir la hoja de cálculo.

¿A qué formatos de archivo se puede exportar después de agregar paneles inmovilizados?

Después de agregar paneles inmovilizados usando IronXL, puede exportar su hoja de cálculo a varios formatos de archivo, como XLSX, CSV y más, usando las funcionalidades de exportación de IronXL.

¿Cómo instalo la biblioteca necesaria para usar paneles inmovilizados en C#?

Debe instalar la biblioteca IronXL desde NuGet para usar la funcionalidad de panel inmovilizado en C#. Visite el sitio web de NuGet y busque IronXL.Excel para descargarla e instalarla.

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 1,686,155 | Versión: 2025.11 recién lanzado