Cómo agregar una tabla nombrada en Excel utilizando 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.

Preguntas Frecuentes

¿Cómo puedo agregar una tabla nombrada a una hoja de cálculo de Excel en C#?

Para agregar una tabla nombrada en C#, use el método AddNamedTable de IronXL. Primero, descargue la biblioteca IronXL desde NuGet. Cargue su libro de Excel, seleccione la hoja de trabajo, defina el rango y luego especifique el nombre de la tabla en el método AddNamedTable. También puede establecer estilos de tabla y visibilidad de filtros.

¿Cuál es el proceso para estilizar una tabla nombrada en IronXL?

En IronXL, después de agregar una tabla nombrada utilizando el método AddNamedTable, puede estilizarla usando el método SetStyle. Elija un estilo de TableStyles como TableStyles.Dark10 para aplicar el aspecto deseado.

¿Cómo recupero todas las tablas nombradas de una hoja de Excel usando IronXL?

Use el método GetNamedTableNames de IronXL para listar todas las tablas nombradas en una hoja de trabajo. Este método devuelve una lista de cadenas, cada una representando una tabla nombrada en la hoja de cálculo de Excel.

¿Cómo puedo recuperar una tabla nombrada específica en C#?

Para recuperar una tabla nombrada específica en IronXL, use el método GetNamedTable con el nombre de la tabla. Esto le permite acceder a la tabla nombrada y sus propiedades para una mayor manipulación.

¿Puedo exportar un archivo de Excel editado a diferentes formatos usando IronXL?

Sí, IronXL le permite exportar un archivo de Excel editado en diversos formatos, asegurando la compatibilidad con diferentes aplicaciones y sistemas.

¿Cuáles son las ventajas de usar tablas nombradas en Excel?

Las tablas nombradas en Excel, facilitadas por IronXL, proporcionan gestión de datos organizada, mayor legibilidad y facilidad de acceso a rangos de datos específicos, mejorando la eficiencia en el análisis y manipulación de datos.

¿Cómo controlo la visibilidad del filtro en una tabla nombrada con IronXL?

En IronXL, puede controlar la visibilidad de los filtros en una tabla nombrada configurando la propiedad ShowFilter. Establézcala en true para mostrar el filtro, o false para ocultarlo.

¿IronXL admite la adición de rangos nombrados además de tablas nombradas?

Sí, IronXL admite tanto tablas nombradas como rangos nombrados, permitiendo una organización y acceso flexibles de datos en hojas de cálculo de Excel.

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