How to Add Named Table
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.
How to Add Named Table
- Download the C# library to add named tables
- Select the target range with workSheet["A1:A5"]
- Utilize
AddNamedTable
method to add named tables - Retrieve named tables in various ways
- Export the edited Excel file in various formats
Get started with IronXL
Start using IronXL in your project today with a free trial.
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")

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
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)
IronXL can also add named ranges. Learn more at How to Add Named Range.
Frequently Asked Questions
What is a named table in Excel?
A named table, also known as an Excel Table, is a range in Excel designated with a name and additional functionality and properties.
How do I add a named table using IronXL?
To add a named table using IronXL, use the AddNamedTable method, providing the table name and range object. You can also set the table style and filter visibility.
What are the steps to create a named table with IronXL?
1. Download the C# library from NuGet. 2. Select the target range in the worksheet. 3. Use the AddNamedTable method to create the table. 4. Optionally set the table style and filter visibility. 5. Save the workbook.
How can I retrieve all named tables in a worksheet using IronXL?
Use the GetNamedTableNames method to retrieve all named tables in the worksheet as a list of strings.
How do I retrieve a specific named table using IronXL?
Use the GetNamedTable method with the table name to retrieve a specific named table in the worksheet.
Can I export the edited Excel file in different formats?
Yes, IronXL allows you to export the edited Excel file in various formats.
What library do I need to download to work with named tables?
You need to download the IronXL Excel library from NuGet to work with named tables in C#.
Can I style the named table using IronXL?
Yes, you can set the style of a named table using the SetStyle method in IronXL.
Is it possible to show or hide filters in a named table using IronXL?
Yes, you can control the visibility of filters in a named table by setting the ShowFilter property in IronXL.
Does IronXL support adding named ranges?
Yes, in addition to named tables, IronXL also supports adding named ranges.