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.


Get started with IronXL

Start using IronXL in your project today with a free trial.

First Step:
green 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.

Frequently Asked Questions

How can I add a named table to an Excel worksheet in C#?

To add a named table in C#, use IronXL's AddNamedTable method. First, download the IronXL library from NuGet. Load your Excel workbook, select the worksheet, define the range, and then specify the table name in the AddNamedTable method. You can also set table styles and filter visibility.

What is the process to style a named table in IronXL?

In IronXL, after adding a named table using the AddNamedTable method, you can style it using the SetStyle method. Choose a style from TableStyles such as TableStyles.Dark10 to apply the desired look.

How do I retrieve all named tables from an Excel sheet using IronXL?

Use IronXL's GetNamedTableNames method to list all named tables in a worksheet. This method returns a list of strings, each representing a named table in the Excel worksheet.

How can I retrieve a specific named table in C#?

To retrieve a specific named table in IronXL, use the GetNamedTable method with the table's name. This allows you to access the named table and its properties for further manipulation.

Can I export an edited Excel file to different formats using IronXL?

Yes, IronXL allows you to export an edited Excel file into various formats, ensuring compatibility with different applications and systems.

What are the advantages of using named tables in Excel?

Named tables in Excel, facilitated by IronXL, provide organized data management, enhanced readability, and ease of access to specific data ranges, improving data analysis and manipulation efficiency.

How do I control filter visibility in a named table with IronXL?

In IronXL, you can control the visibility of filters in a named table by setting the ShowFilter property. Set it to true to display the filter, or false to hide it.

Does IronXL support adding named ranges in addition to named tables?

Yes, IronXL supports both named tables and named ranges, allowing for flexible data organization and access in Excel spreadsheets.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.