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

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 to my spreadsheet?

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 in a C# application?

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?

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?

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 in my spreadsheet?

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?

Yes, you can control the visibility of filters in a named table by setting the ShowFilter property in IronXL.

Does the library support adding named ranges?

Yes, in addition to named tables, IronXL also supports adding named ranges.

Chaknith related to Retrieve Specific Named Table
Software Engineer
Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.