Comment créer un fichier 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

Veuillez noterOnly 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).

Questions Fréquemment Posées

Comment ajouter un volet figé à une feuille de calcul en utilisant C# ?

Pour ajouter un volet figé à une feuille de calcul en C#, utilisez la méthode CreateFreezePane de IronXL. Spécifiez la colonne et la ligne de départ, par exemple workSheet.CreateFreezePane(1, 4), ce qui verrouille les lignes 1 à 4 et la colonne A.

Quel est l'objectif d'utiliser des volets figés dans Excel ?

Les volets figés sont utilisés pour verrouiller des lignes ou colonnes spécifiques en place, leur permettant de rester visibles lors du défilement d'autres parties de la feuille de calcul. C'est particulièrement utile pour garder les en-têtes ou les données clés en vue lors de la navigation dans des ensembles de données volumineux.

Comment puis-je supprimer les volets figés d'une feuille de calcul par programmation ?

Pour supprimer les volets figés par programmation en utilisant IronXL, utilisez la méthode RemovePane, qui efface tous les volets figés existants de la feuille de calcul.

Les volets figés peuvent-ils être appliqués aux anciens formats de fichiers Excel ?

Non, les volets figés créés en utilisant IronXL ne fonctionnent pas avec les formats de fichiers Microsoft Excel des versions 97-2003 (.xls).

Est-il possible de créer plusieurs volets figés dans une même feuille de travail ?

Non, un seul volet figé peut être appliqué à la fois dans une feuille de travail. Toute nouvelle création de volet figé écrasera la précédente.

Comment puis-je créer un volet figé avec fonctionnalité de pré-défilement ?

IronXL vous permet de créer un volet figé avec pré-défilement en utilisant la méthode CreateFreezePane avec quatre paramètres. Par exemple, workSheet.CreateFreezePane(5, 2, 6, 7) crée un volet figé à partir des colonnes A-E et des lignes 1-2, avec un défilement qui commence de la colonne G et ligne 8 à l'ouverture de la feuille de calcul.

Quels formats de fichiers peuvent être exportés après l'ajout de volets figés ?

Après avoir ajouté des volets figés en utilisant IronXL, vous pouvez exporter votre feuille de calcul vers divers formats de fichiers, tels que XLSX, CSV, et plus, en utilisant les fonctionnalités d'exportation de IronXL.

Comment puis-je installer la bibliothèque nécessaire pour utiliser les volets figés en C# ?

Vous devez installer la bibliothèque IronXL depuis NuGet pour utiliser la fonctionnalité de volet figé en C#. Visitez le site web de NuGet et recherchez IronXL.Excel pour le télécharger et l'installer.

Chaknith Bin
Ingénieur logiciel
Chaknith travaille sur IronXL et IronBarcode. Il a une expertise approfondie en C# et .NET, aidant à améliorer le logiciel et à soutenir les clients. Ses idées issues des interactions avec les utilisateurs contribuent à de meilleurs produits, documentation et expérience globale.
Prêt à commencer?
Nuget Téléchargements 1,686,155 | Version : 2025.11 vient de sortir