How to Add Named Table

by Chaknith Bin

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


C# NuGet Library for Excel

Install with NuGet

Install-Package IronXL.Excel
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

C# NuGet Library for Excel

Install with NuGet

Install-Package IronXL.Excel
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

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

First Step:
green arrow pointer

Check out IronXL on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming Excel with C#.

C# NuGet Library for Excel nuget.org/packages/IronXL.Excel/
Install-Package IronXL.Excel

Consider installing the IronXL DLL directly. Download and manually install it for your project or GAC form: IronXL.zip

Dll Img related to How to Add Named Table

Manually install into your project

Download DLL

Add Named Table Example

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

:path=/static-assets/excel/content-code-examples/how-to/named-table-add-named-table.cs
using IronXL;
using IronXL.Styles;

WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Add data
workSheet["A2:C5"].StringValue = "Text";

// Configure named table
var selectedRange = workSheet["A1:C5"];
bool showFilter = false;
var tableStyle = TableStyle.TableStyleDark1;

// Add named table
workSheet.AddNamedTable("table1", selectedRange, showFilter, tableStyle);

workBook.SaveAs("addNamedTable.xlsx");
Imports IronXL
Imports IronXL.Styles

Private workBook As WorkBook = WorkBook.Create()
Private workSheet As WorkSheet = workBook.DefaultWorkSheet

' Add data
Private workSheet("A2:C5").StringValue = "Text"

' Configure named table
Private selectedRange = workSheet("A1:C5")
Private showFilter As Boolean = False
Private tableStyle = TableStyle.TableStyleDark1

' Add named table
workSheet.AddNamedTable("table1", selectedRange, showFilter, tableStyle)

workBook.SaveAs("addNamedTable.xlsx")
VB   C#
Named Table

Retrieve Named Table Example

Retrieve All Named Table

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

:path=/static-assets/excel/content-code-examples/how-to/named-table-retrieve-all-named-table.cs
using IronXL;

WorkBook workBook = WorkBook.Load("addNamedTable.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Get all named table
var namedTableList = workSheet.GetNamedTableNames();
Imports IronXL

Private workBook As WorkBook = WorkBook.Load("addNamedTable.xlsx")
Private workSheet As WorkSheet = workBook.DefaultWorkSheet

' Get all named table
Private namedTableList = workSheet.GetNamedTableNames()
VB   C#

Retrieve Specific Named Table

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

:path=/static-assets/excel/content-code-examples/how-to/named-table-retrieve-specific-named-table.cs
using IronXL;

WorkBook workBook = WorkBook.Load("addNamedTable.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Get named table
var namedRangeAddress = workSheet.GetNamedTable("table1");
Imports IronXL

Private workBook As WorkBook = WorkBook.Load("addNamedTable.xlsx")
Private workSheet As WorkSheet = workBook.DefaultWorkSheet

' Get named table
Private namedRangeAddress = workSheet.GetNamedTable("table1")
VB   C#

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

Chaknith related to Retrieve Specific Named Table

Chaknith Bin

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.