Excel'de C# Kullanarak Adlandırılmış Tablo Nasıl Eklenir
C# kullanarak Excel'e adlandırılmış bir tablo eklemek için, IronXL'nin AddNamedTable yöntemini tablo adı, aralık ve isteğe bağlı stil parametreleriyle kullanın; böylece tek bir yöntem çağrısıyla yapılandırılmış veri yönetimi sağlayabilirsiniz.
Bir adlandırılmış tablo, ayrıca bir Excel Tablosu olarak da bilinir, belirli bir isme sahip bir tür aralığa atıfta bulunur ve buna ek olarak çeşitli işlevsellik ve özelliklere sahiptir. Adlandırılmış tablolar gelişmiş veri organizasyon yetenekleri, otomatik biçimlendirme, yerleşik filtreleme ve Excel formülleriyle sorunsuz entegrasyon sağlar—bu yüzden Excel otomasyon iş akışlarında yapısal veri kümelerini yönetmek için esastır.
Hızlı Başlangıç: Tek Bir Satırda Bir Tablo Oluştur ve Adlandır
Bu örnek, IronXL kullanarak çalışma sayfanıza ne kadar kolay bir şekilde adlandırılmış bir tablo ekleyebileceğinizi gösterir—adını, aralığını, filtre görünürlüğünü ve stilini tek bir açık yöntem çağrısıyla tanımlayın.
-
IronXL aşağıdaki NuGet Paket Yöneticisi ile yükleyin
PM > Install-Package IronXL.Excel -
Bu kod parçacığını kopyalayın ve çalıştırın.
var table = workSheet.AddNamedTable("MyTable", workSheet.GetRange("A1:B5"), showFilter: true, tableStyle: IronXl.Styles.TableStyles.Medium2); -
Canlı ortamınızda test için dağıtım yapın
Ücretsiz deneme ile bugün projenizde IronXL kullanmaya başlayın
Asgari İş Akışı (5 adım)
- Adlandırılmış tablolar eklemek için C# kütüphanesini indirin
- Hedef aralığı workSheet["A1:A5"] ile seçin
AddNamedTablemetodunu kullanarak adlandırılmış tablolar ekleyin- Çeşitli yollarla adlandırılmış tabloları alın
- Düzenlenmiş Excel dosyasını çeşitli formatlarda dışa aktarın
Excel Çalışma Sayfama Adlandırılmış Tabloyu Nasıl Eklerim?
Adlandırılmış bir tablo eklemek için AddNamedTable yöntemini kullanın. Metot, tablo adını dize olarak ve aralık nesnesini gerektirir. Ayrıca tablo stilini belirtme ve filtreyi gösterme seçeneğiniz de vardır. Bu işlevsellik, yapılandırılmış verilerin uygun şekilde düzenlenmesi gereken DataSet ve DataTable içe aktarmalarıyla çalışırken özellikle kullanışlıdır.
// 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");
Imports IronXL
Imports IronXl.Styles
' Load the Excel workbook
Dim workbook = WorkBook.Load("example.xlsx")
' Select the worksheet
Dim workSheet = workbook.WorkSheets.First()
' Define the range for the named table
Dim range = workSheet("A1:B10")
' Add a named table with the specified name and range
Dim 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")
Adlandırılmış tablolar, TableStyles numaralandırması aracılığıyla çeşitli stil seçeneklerini destekler. Diğer biçimlendirme özelliklerini tamamlayan, anında profesyonel format uygulayabilirsiniz, örneğin hücre stilizasyonu ve kenarlıklar gibi. İşte farklı tablo stil uygulamalarını gösteren bir örnek:
// Example: Creating multiple styled named tables
using IronXL;
using IronXl.Styles;
var workbook = WorkBook.Create();
var sheet = workbook.CreateWorkSheet("SalesData");
// Add sample data
sheet["A1"].Value = "Product";
sheet["B1"].Value = "Sales";
sheet["C1"].Value = "Revenue";
// Populate data rows
for (int i = 2; i <= 10; i++)
{
sheet[$"A{i}"].Value = $"Product {i-1}";
sheet[$"B{i}"].IntValue = i * 100;
sheet[$"C{i}"].DecimalValue = i * 250.50m;
}
// Create a light-styled table
var salesTable = sheet.AddNamedTable("SalesTable", sheet["A1:C10"],
showFilter: true,
tableStyle: TableStyles.Light15);
// Create another table with dark styling
sheet["E1"].Value = "Region";
sheet["F1"].Value = "Performance";
var regionTable = sheet.AddNamedTable("RegionData", sheet["E1:F5"],
showFilter: false,
tableStyle: TableStyles.Dark3);
workbook.SaveAs("styled_tables.xlsx");
// Example: Creating multiple styled named tables
using IronXL;
using IronXl.Styles;
var workbook = WorkBook.Create();
var sheet = workbook.CreateWorkSheet("SalesData");
// Add sample data
sheet["A1"].Value = "Product";
sheet["B1"].Value = "Sales";
sheet["C1"].Value = "Revenue";
// Populate data rows
for (int i = 2; i <= 10; i++)
{
sheet[$"A{i}"].Value = $"Product {i-1}";
sheet[$"B{i}"].IntValue = i * 100;
sheet[$"C{i}"].DecimalValue = i * 250.50m;
}
// Create a light-styled table
var salesTable = sheet.AddNamedTable("SalesTable", sheet["A1:C10"],
showFilter: true,
tableStyle: TableStyles.Light15);
// Create another table with dark styling
sheet["E1"].Value = "Region";
sheet["F1"].Value = "Performance";
var regionTable = sheet.AddNamedTable("RegionData", sheet["E1:F5"],
showFilter: false,
tableStyle: TableStyles.Dark3);
workbook.SaveAs("styled_tables.xlsx");
Imports IronXL
Imports IronXl.Styles
Module Module1
Sub Main()
Dim workbook = WorkBook.Create()
Dim sheet = workbook.CreateWorkSheet("SalesData")
' Add sample data
sheet("A1").Value = "Product"
sheet("B1").Value = "Sales"
sheet("C1").Value = "Revenue"
' Populate data rows
For i As Integer = 2 To 10
sheet($"A{i}").Value = $"Product {i - 1}"
sheet($"B{i}").IntValue = i * 100
sheet($"C{i}").DecimalValue = i * 250.5D
Next
' Create a light-styled table
Dim salesTable = sheet.AddNamedTable("SalesTable", sheet("A1:C10"),
showFilter:=True,
tableStyle:=TableStyles.Light15)
' Create another table with dark styling
sheet("E1").Value = "Region"
sheet("F1").Value = "Performance"
Dim regionTable = sheet.AddNamedTable("RegionData", sheet("E1:F5"),
showFilter:=False,
tableStyle:=TableStyles.Dark3)
workbook.SaveAs("styled_tables.xlsx")
End Sub
End Module
Çalışma Sayfamdan Adlandırılmış Tabloları Nasıl Alabilirim?
Çalışma Sayfasındaki Tüm Adlandırılmış Tabloları Döndüren Hangi Metottur?
GetNamedTableNames yöntemi, çalışma sayfasındaki tüm adlandırılmış tabloları bir dize listesi olarak döndürür. Bu özellikle birden fazla tablo içeren çalışma kitapları ile veya dinamik veri yapılarıyla çalışma sayfalarını yönetirken çalışırken yararlıdır.
// 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
Spesifik Bir Adlandırılmış Tabloya İsmiyle Nasıl Erişirim?
Çalışma sayfasındaki belirli bir adlı tabloyu almak için GetNamedTable yöntemini kullanın. Elde edildikten sonra, çeşitli özelliklere erişebilir ve hücre aralıklarını sıralama veya koşullu biçimlendirme uygulama gibi işlemler gerçekleştirebilirsiniz.
// 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)
Tablo Verileriyle Çalışma
Adlandırılmış tablolar güçlü veri manipülasyon yetenekleri sağlar. İşte tablo verileriyle nasıl çalışabileceğinize dair kapsamlı bir örnek:
// Advanced named table operations
using IronXL;
using System.Linq;
var workbook = WorkBook.Load("sales_data.xlsx");
var sheet = workbook.DefaultWorkSheet;
// Create a named table from existing data
var dataRange = sheet["A1:D20"];
var salesTable = sheet.AddNamedTable("MonthlySales", dataRange, true);
// Access table data for calculations
var tableRange = salesTable.TableRange;
// Sum values in a specific column (assuming column C contains numeric data)
decimal totalSales = 0;
for (int row = 2; row <= tableRange.RowCount; row++)
{
var cellValue = sheet[$"C{row}"].DecimalValue;
totalSales += cellValue;
}
// Add summary row
var summaryRow = tableRange.RowCount + 1;
sheet[$"B{summaryRow}"].Value = "Total:";
sheet[$"C{summaryRow}"].Value = totalSales;
// Apply formatting to the summary row
sheet[$"B{summaryRow}:D{summaryRow}"].Style.Font.Bold = true;
sheet[$"B{summaryRow}:D{summaryRow}"].Style.SetBackgroundColor("#FFE599");
workbook.SaveAs("sales_with_summary.xlsx");
// Advanced named table operations
using IronXL;
using System.Linq;
var workbook = WorkBook.Load("sales_data.xlsx");
var sheet = workbook.DefaultWorkSheet;
// Create a named table from existing data
var dataRange = sheet["A1:D20"];
var salesTable = sheet.AddNamedTable("MonthlySales", dataRange, true);
// Access table data for calculations
var tableRange = salesTable.TableRange;
// Sum values in a specific column (assuming column C contains numeric data)
decimal totalSales = 0;
for (int row = 2; row <= tableRange.RowCount; row++)
{
var cellValue = sheet[$"C{row}"].DecimalValue;
totalSales += cellValue;
}
// Add summary row
var summaryRow = tableRange.RowCount + 1;
sheet[$"B{summaryRow}"].Value = "Total:";
sheet[$"C{summaryRow}"].Value = totalSales;
// Apply formatting to the summary row
sheet[$"B{summaryRow}:D{summaryRow}"].Style.Font.Bold = true;
sheet[$"B{summaryRow}:D{summaryRow}"].Style.SetBackgroundColor("#FFE599");
workbook.SaveAs("sales_with_summary.xlsx");
Imports IronXL
Imports System.Linq
Dim workbook = WorkBook.Load("sales_data.xlsx")
Dim sheet = workbook.DefaultWorkSheet
' Create a named table from existing data
Dim dataRange = sheet("A1:D20")
Dim salesTable = sheet.AddNamedTable("MonthlySales", dataRange, True)
' Access table data for calculations
Dim tableRange = salesTable.TableRange
' Sum values in a specific column (assuming column C contains numeric data)
Dim totalSales As Decimal = 0
For row As Integer = 2 To tableRange.RowCount
Dim cellValue = sheet($"C{row}").DecimalValue
totalSales += cellValue
Next
' Add summary row
Dim summaryRow = tableRange.RowCount + 1
sheet($"B{summaryRow}").Value = "Total:"
sheet($"C{summaryRow}").Value = totalSales
' Apply formatting to the summary row
sheet($"B{summaryRow}:D{summaryRow}").Style.Font.Bold = True
sheet($"B{summaryRow}:D{summaryRow}").Style.SetBackgroundColor("#FFE599")
workbook.SaveAs("sales_with_summary.xlsx")
Diğer IronXL Özellikleri ile Entegrasyon
Adlandırılmış tablolar, diğer IronXL özellikleriyle sorunsuz bir şekilde çalışır. Bunları formüller ile dinamik hesaplamalar yapmak için birleştirebilir veya grafikler oluştururken veri kaynakları olarak kullanabilirsiniz. Ayrıca farklı formatlara aktarmadan önce verileri düzenlemek için mükemmeldirler.
// Example: Named table with formulas
using IronXL;
var workbook = WorkBook.Create();
var sheet = workbook.CreateWorkSheet("Analysis");
// Create data structure
sheet["A1"].Value = "Item";
sheet["B1"].Value = "Quantity";
sheet["C1"].Value = "Price";
sheet["D1"].Value = "Total";
// Add sample data
for (int i = 2; i <= 6; i++)
{
sheet[$"A{i}"].Value = $"Item {i-1}";
sheet[$"B{i}"].IntValue = i * 10;
sheet[$"C{i}"].DecimalValue = i * 15.99m;
// Add formula to calculate total
sheet[$"D{i}"].Formula = $"=B{i}*C{i}";
}
// Create named table including the formula column
var priceTable = sheet.AddNamedTable("PriceCalculations", sheet["A1:D6"],
showFilter: true,
tableStyle: TableStyles.Medium9);
// Add a grand total formula
sheet["C7"].Value = "Grand Total:";
sheet["D7"].Formula = "=SUM(D2:D6)";
sheet["D7"].Style.Font.Bold = true;
workbook.SaveAs("table_with_formulas.xlsx");
// Example: Named table with formulas
using IronXL;
var workbook = WorkBook.Create();
var sheet = workbook.CreateWorkSheet("Analysis");
// Create data structure
sheet["A1"].Value = "Item";
sheet["B1"].Value = "Quantity";
sheet["C1"].Value = "Price";
sheet["D1"].Value = "Total";
// Add sample data
for (int i = 2; i <= 6; i++)
{
sheet[$"A{i}"].Value = $"Item {i-1}";
sheet[$"B{i}"].IntValue = i * 10;
sheet[$"C{i}"].DecimalValue = i * 15.99m;
// Add formula to calculate total
sheet[$"D{i}"].Formula = $"=B{i}*C{i}";
}
// Create named table including the formula column
var priceTable = sheet.AddNamedTable("PriceCalculations", sheet["A1:D6"],
showFilter: true,
tableStyle: TableStyles.Medium9);
// Add a grand total formula
sheet["C7"].Value = "Grand Total:";
sheet["D7"].Formula = "=SUM(D2:D6)";
sheet["D7"].Style.Font.Bold = true;
workbook.SaveAs("table_with_formulas.xlsx");
Imports IronXL
Dim workbook = WorkBook.Create()
Dim sheet = workbook.CreateWorkSheet("Analysis")
' Create data structure
sheet("A1").Value = "Item"
sheet("B1").Value = "Quantity"
sheet("C1").Value = "Price"
sheet("D1").Value = "Total"
' Add sample data
For i As Integer = 2 To 6
sheet($"A{i}").Value = $"Item {i - 1}"
sheet($"B{i}").IntValue = i * 10
sheet($"C{i}").DecimalValue = i * 15.99D
' Add formula to calculate total
sheet($"D{i}").Formula = $"=B{i}*C{i}"
Next
' Create named table including the formula column
Dim priceTable = sheet.AddNamedTable("PriceCalculations", sheet("A1:D6"),
showFilter:=True,
tableStyle:=TableStyles.Medium9)
' Add a grand total formula
sheet("C7").Value = "Grand Total:"
sheet("D7").Formula = "=SUM(D2:D6)"
sheet("D7").Style.Font.Bold = True
workbook.SaveAs("table_with_formulas.xlsx")
IronXL ayrıca adlandırılmış aralıklar da ekleyebilir. Daha fazla bilgi edinin İsimlendirilmiş Aralık Nasıl Eklenir adresinde.
Sıkça Sorulan Sorular
Excel'de isimlendirilen tablo nedir?
Excel'de isimlendirilen bir tablo, belirli bir adı olan ve ek işlevsellik içeren özel bir aralıktır. IronXL, C# içinde bu tabloları programatik olarak oluşturmanıza olanak tanır, gelişmiş veri düzenleme kapasiteleri, otomatik formatlama, yerleşik filtreleme ve Excel formülleri ile sorunsuz entegrasyon sağlar.
C# kullanarak Excel çalışma sayfasına nasıl bir isimlendirilen tablo eklerim?
IronXL kullanarak isimlendirilen bir tablo eklemek için AddNamedTable yöntemini kullanın. Bu yöntem, tablo adını bir dize olarak ve bir aralık nesnesi olarak gerektirir. Opsyonel olarak tablo stili ve filtre görünürlüğünü belirtebilirsiniz. Örneğin: workSheet.AddNamedTable('MyTable', workSheet.GetRange('A1:B5'), showFilter: true, tableStyle: IronXl.Styles.TableStyles.Medium2).
İsimlendirilen tablolara özel stil uygulayabilir miyim?
Evet, IronXL, isimlendirilen tablolar için TableStyles enumarasyonuyla çeşitli stil seçeneklerini destekler. Dark10, Medium2 ve diğer ön tanımlı tablo stillerini kullanarak profesyonel formatlamayı anında uygulayabilirsiniz. SetStyle yöntemini kullanarak veya tablo oluştururken tableStyle parametresini belirterek bunu yapabilirsiniz.
İsimlendirilen tablolarda filtrelerin gösterilmesi veya gizlenmesi mümkün mü?
Kesinlikle! IronXL, isimlendirilen tablolarda filtre görünürlüğünü kontrol etmenizi sağlar. showFilter parametresini AddNamedTable yönteminde doğrudan belirtilerek gösterilebilir.
İsimlendirilen bir tablo oluşturmak için gerekli parametreler nelerdir?
IronXL'deki AddNamedTable yöntemi, iki önemli parametre: tablo adı (dize olarak) ve tablo alanını tanımlayan aralık nesnesi gerektirir. Opsiyonel parametreler arasında showFilter (bool) ve tableStyle (TableStyles enumarasyonundan) bulunur.
Aynı çalışma sayfasında birden fazla stil uygulanmış isimlendirilen tablo oluşturabilir miyim?
Evet, IronXL, aynı çalışma sayfasında farklı stillere sahip birden fazla isimlendirilen tablo oluşturmanıza izin verir. Her tablo kendi benzersiz adını, aralığını, stilini ve filtre ayarlarını içerebilir, bu da aynı Excel dosyasında farklı veri kümelerini organize etmek için mükemmeldir.

