如何添加命名表格
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 也可以添加命名範圍。 了解更多信息,请访问如何新增命名範圍.