如何添加命名表
This article was translated from English: Does it need improvement?
TranslatedView the article in English
命名表通常也称为 Excel 表,指的是一种特定类型的范围,该范围已指定名称,并具有与之相关的附加功能和属性。
如何添加命名表
- 下载 C# 库以添加命名表格
- 选择目标范围 工作表 ["A1:A5"]
- 利用
添加命名表
方法添加命名表格 - 以各种方式读取命名表
- 将编辑好的 Excel 文件导出为各种格式
开始使用IronXL
立即在您的项目中开始使用IronXL,并享受免费试用。
添加命名表示例
要添加一个命名表,请使用 AddNamedTable
方法。 该方法需要命名表的名称作为文本,范围对象。 用户还可以选择指定表格样式以及是否显示筛选器。
: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#
检索命名表示例
检索所有命名表
GetNamedTableNames
方法将返回工作表中所有命名表格的字符串列表。
: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#
检索特定命名表格
使用 GetNamedTable
方法来检索工作表中指定的命名表。
: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也可以添加命名范围。 了解更多,请访问如何添加命名范围.