Comment ajouter une table nommée dans Excel en utilisant C# | IronXL

How to Add Named Table

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

A named table is also commonly known as an Excel Table, which refers to a specific type of range that has been designated with a name and has additional functionality and properties associated with it.

Quickstart: Create and Name a Table in One Line

This example shows how effortlessly you can add a named table in your worksheet using IronXL—define the name, range, filter visibility, and style all in a single clear method call.

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.

    var table = workSheet.AddNamedTable("MyTable", workSheet.GetRange("A1:B5"), showFilter: true, tableStyle: IronXL.Styles.TableStyles.Medium2);
  3. Deploy to test on your live environment

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


Add Named Table Example

To add a named table, use the AddNamedTable method. The method requires the name of the table as a string and the range object. The user also has the option to specify the table style and whether to show the filter or not.

// Example code to add a named table using IronXL
using IronXL;
using IronXL.Styles;

// Load the Excel workbook
var workbook = WorkBook.Load("example.xlsx");
// Select the worksheet
var workSheet = workbook.WorkSheets.First();

// Define the range for the named table
var range = workSheet["A1:B10"];

// Add a named table with the specified name and range
var namedTable = workSheet.AddNamedTable("MyTable", range);

// Optionally, set table style and visibility of the filter
namedTable.SetStyle(TableStyles.Dark10);
namedTable.ShowFilter = true;

// Save the modified workbook
workbook.SaveAs("modified_example.xlsx");
// Example code to add a named table using IronXL
using IronXL;
using IronXL.Styles;

// Load the Excel workbook
var workbook = WorkBook.Load("example.xlsx");
// Select the worksheet
var workSheet = workbook.WorkSheets.First();

// Define the range for the named table
var range = workSheet["A1:B10"];

// Add a named table with the specified name and range
var namedTable = workSheet.AddNamedTable("MyTable", range);

// Optionally, set table style and visibility of the filter
namedTable.SetStyle(TableStyles.Dark10);
namedTable.ShowFilter = true;

// Save the modified workbook
workbook.SaveAs("modified_example.xlsx");
' Example code to add a named table using IronXL
Imports IronXL
Imports IronXL.Styles

' Load the Excel workbook
Private workbook = WorkBook.Load("example.xlsx")
' Select the worksheet
Private workSheet = workbook.WorkSheets.First()

' Define the range for the named table
Private range = workSheet("A1:B10")

' Add a named table with the specified name and range
Private namedTable = workSheet.AddNamedTable("MyTable", range)

' Optionally, set table style and visibility of the filter
namedTable.SetStyle(TableStyles.Dark10)
namedTable.ShowFilter = True

' Save the modified workbook
workbook.SaveAs("modified_example.xlsx")
$vbLabelText   $csharpLabel
Named Table

Retrieve Named Table Example

Retrieve All Named Tables

The GetNamedTableNames method will return all named tables in the worksheet as a list of strings.

// Example code to retrieve all named table names using IronXL
using IronXL;

// Load the Excel workbook
var workbook = WorkBook.Load("example.xlsx");
// Select the worksheet
var workSheet = workbook.WorkSheets.First();

// Retrieve all named table names
var tableNames = workSheet.GetNamedTableNames();

// Output each table name
foreach (var name in tableNames)
{
    Console.WriteLine("Named Table: " + name);
}
// Example code to retrieve all named table names using IronXL
using IronXL;

// Load the Excel workbook
var workbook = WorkBook.Load("example.xlsx");
// Select the worksheet
var workSheet = workbook.WorkSheets.First();

// Retrieve all named table names
var tableNames = workSheet.GetNamedTableNames();

// Output each table name
foreach (var name in tableNames)
{
    Console.WriteLine("Named Table: " + name);
}
' Example code to retrieve all named table names using IronXL
Imports IronXL

' Load the Excel workbook
Private workbook = WorkBook.Load("example.xlsx")
' Select the worksheet
Private workSheet = workbook.WorkSheets.First()

' Retrieve all named table names
Private tableNames = workSheet.GetNamedTableNames()

' Output each table name
For Each name In tableNames
	Console.WriteLine("Named Table: " & name)
Next name
$vbLabelText   $csharpLabel

Retrieve Specific Named Table

Use the GetNamedTable method to retrieve a specific named table in the worksheet.

// Example code to retrieve a specific named table using IronXL
using IronXL;

// Load the Excel workbook
var workbook = WorkBook.Load("example.xlsx");
// Select the worksheet
var workSheet = workbook.WorkSheets.First();

// Retrieve a specific named table
var namedTable = workSheet.GetNamedTable("MyTable");

// Output some information about the table
Console.WriteLine("Named Table: " + namedTable.Name);
Console.WriteLine("Rows: " + namedTable.Rows);
// Example code to retrieve a specific named table using IronXL
using IronXL;

// Load the Excel workbook
var workbook = WorkBook.Load("example.xlsx");
// Select the worksheet
var workSheet = workbook.WorkSheets.First();

// Retrieve a specific named table
var namedTable = workSheet.GetNamedTable("MyTable");

// Output some information about the table
Console.WriteLine("Named Table: " + namedTable.Name);
Console.WriteLine("Rows: " + namedTable.Rows);
' Example code to retrieve a specific named table using IronXL
Imports IronXL

' Load the Excel workbook
Private workbook = WorkBook.Load("example.xlsx")
' Select the worksheet
Private workSheet = workbook.WorkSheets.First()

' Retrieve a specific named table
Private namedTable = workSheet.GetNamedTable("MyTable")

' Output some information about the table
Console.WriteLine("Named Table: " & namedTable.Name)
Console.WriteLine("Rows: " & namedTable.Rows)
$vbLabelText   $csharpLabel

IronXL can also add named ranges. Learn more at How to Add Named Range.

Questions Fréquemment Posées

Comment puis-je ajouter une table nommée à une feuille de calcul Excel en C# ?

Pour ajouter une table nommée en C#, utilisez la méthode AddNamedTable d'IronXL. Tout d'abord, téléchargez la bibliothèque IronXL depuis NuGet. Chargez votre classeur Excel, sélectionnez la feuille de calcul, définissez la plage, puis spécifiez le nom de la table dans la méthode AddNamedTable. Vous pouvez également définir les styles de table et la visibilité des filtres.

Quel est le processus pour styliser une table nommée dans IronXL ?

Dans IronXL, après avoir ajouté une table nommée en utilisant la méthode AddNamedTable, vous pouvez la styliser en utilisant la méthode SetStyle. Choisissez un style parmi TableStyles tel que TableStyles.Dark10 pour appliquer l'apparence désirée.

Comment puis-je récupérer toutes les tables nommées d'une feuille Excel en utilisant IronXL ?

Utilisez la méthode GetNamedTableNames d'IronXL pour lister toutes les tables nommées dans une feuille de calcul. Cette méthode renvoie une liste de chaînes de caractères, chacune représentant une table nommée dans la feuille Excel.

Comment puis-je récupérer une table nommée spécifique en C# ?

Pour récupérer une table nommée spécifique dans IronXL, utilisez la méthode GetNamedTable avec le nom de la table. Cela vous permet d'accéder à la table nommée et à ses propriétés pour une manipulation ultérieure.

Puis-je exporter un fichier Excel modifié vers différents formats en utilisant IronXL ?

Oui, IronXL vous permet d'exporter un fichier Excel modifié dans divers formats, assurant la compatibilité avec différentes applications et systèmes.

Quels sont les avantages de l'utilisation de tables nommées dans Excel ?

Les tables nommées dans Excel, facilitées par IronXL, offrent une gestion des données organisée, une meilleure lisibilité et un accès facile à des plages de données spécifiques, améliorant ainsi l'efficacité de l'analyse et de la manipulation des données.

Comment puis-je contrôler la visibilité des filtres dans une table nommée avec IronXL ?

Dans IronXL, vous pouvez contrôler la visibilité des filtres dans une table nommée en définissant la propriété ShowFilter. Réglez-la sur true pour afficher le filtre, ou sur false pour le masquer.

IronXL prend-il en charge l'ajout de plages nommées en plus des tables nommées ?

Oui, IronXL supporte à la fois les tables nommées et les plages nommées, permettant une organisation et un accès flexibles des données dans les feuilles de calcul Excel.

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