Excel'de C# Kullanarak İsimlendirilen Tablo Nasıl Eklenir
C# kullanarak Excel'de adlandırılmış bir tablo eklemek için, tabloları ad, aralık ve isteğe bağlı stil parametreleriyle yönetmeyi sağlayan bir yöntem olan IronXL'nin AddNamedTable yöntemi kullanılabilir.
Bir isimlendirilmiş tablo, ayrıca bir Excel Tablo olarak da bilinir; bu, adı verilmiş ve ek işlevsellik ve özelliklerle ilişkili bir tür aralık için tanımlanmıştır. İsimlendirilmiş tablolar, gelişmiş veri organizasyonu yetenekleri, otomatik biçimlendirme, yerleşik filtreleme ve Excel formülleriyle sorunsuz entegrasyon sağlar—bunlar, Excel otomasyon iş akışlarındaki yapılandırılmış veri setlerini yönetmek için vazgeçilmez kılar.
Hızlı Başlangıç: Tek Satırda Bir Tablo Oluşturun ve Adlandırın
Bu örnek, çalışma sayfanıza IronXL kullanarak nasıl kolayca bir isimlendirilmiş tablo ekleyebileceğinizi gösterir—tablo adını, aralığı, filtre görünürlüğünü ve stilini tek bir net yöntem çağrısında tanımlayın.
-
NuGet Paket Yöneticisi ile https://www.nuget.org/packages/IronXl.Excel yükleyin
PM > Install-Package IronXl.Excel -
Bu kod parçasını kopyalayıp ç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 etmek için dağıtın
Bugün projenizde IronXL kullanmaya başlayın ücretsiz deneme ile
Minimal Is Akisi (5 adimda)
- İsimlendirilen tablolar eklemek için C# kütüphanesini indirin
workSheet["A1:A5"]ile hedef aralığı seçinAddNamedTableyöntemini kullanarak isimlendirilen tablolar ekleyin- Adlandırılmış tabloları çeşitli yollarla alın
- Düzenlenmiş Excel dosyasını çeşitli formatlarda dışa aktarın
Excel Çalışma Sayfama Nasıl İsimlendirilen Bir Tablo Eklerim?
Bir adlandırılmış tablo eklemek için AddNamedTable yöntemini kullanın. Yöntem, tablo adını bir dize olarak ve aralık nesnesini gerektirir. Tablo stilini belirtme ve filtreyi gösterme seçeneğine de sahipsiniz. Bu işlevsellik, yapılandırılmış verilerin doğru bir şekilde düzenlenmesi gereken DataSet ve DataTable ithalatları ile ç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. Bu, diğer biçimlendirme özellikleriyle mükemmel bir şekilde uyumlu olan profesyonel biçimlendirmeyi anında uygulamanızı sağlar, örneğin hücre stili ve kenarlıkları gibi. 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 İsimlendirilen Tabloları Nasıl Alabilirim?
Bir Çalışma Sayfasındaki Tüm İsimlendirilen Tabloları Hangi Yöntem Döndürür?
GetNamedTableNames yöntemi, çalışma sayfasındaki tüm adlandırılmış tabloları bir dizi olarak döndürür. Bu, birden fazla tablo içeren çalışma kitaplarıyla çalışırken veya dinamik veri yapılarıyla çalışma sayfalarını yönetirken özellikle kullanışlı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
Belirli Bir Adlandırılmış Tabloya Adına Göre Nasıl Ulaşırım?
Çalışma sayfasındaki belirli bir adlandırılmış tabloyu almak için GetNamedTable metodunu kullanın. Alındıktan sonra, çeşitli özelliklere erişebilir ve hücre aralıklarını sıralama veya şartlı 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ışılacağını gösteren 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 Özellikleriyle Entegrasyon
Adlandırılmış tablolar, diğer IronXL özellikleriyle sorunsuz bir şekilde çalışır. Onları, dinamik hesaplamalar için formüllerle birleştirebilir veya grafik oluştururken veri kaynağı olarak kullanabilirsiniz. Farklı formatlara dışa aktarmadan önce veriyi organize etmek için de mükemmeldir.
// 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 ekleyebilir. Adlandırılmış Aralık Nasıl Eklenir hakkında daha fazla bilgi edinin.
Sıkça Sorulan Sorular
Excel'de adlandırılmış bir tablo nedir?
Excel'de adlandırılmış bir tablo, bir isimle tanımlanmış ve ek işlevsellik içeren belirli bir tür aralıktır. IronXL, bu tabloları C#'ta programlı bir şekilde oluşturmanıza olanak tanır, gelişmiş veri organizasyon yetenekleri, otomatik biçimlendirme, yerleşik filtreleme ve Excel formülleriyle sorunsuz entegrasyon sağlar.
C# kullanarak Excel çalışma sayfasına nasıl adlandırılmış bir tablo eklerim?
IronXL kullanarak adlandırılmış bir tablo eklemek için, AddNamedTable metodunu kullanın. Bu metod, tablo ismini bir dize olarak ve bir aralık nesnesi gerektirir. İsteğe bağlı olarak tablo stilini ve filtre görünürlüğünü belirleyebilirsiniz. Örneğin: workSheet.AddNamedTable("MyTable", workSheet.GetRange("A1:B5"), showFilter: true, tableStyle: IronXl.Styles.TableStyles.Medium2).
Adlandırılmış tablolara özel stiller uygulayabilir miyim?
Evet, IronXL, adlandırılmış tablolar için TableStyles numaralandırması aracılığıyla çeşitli stil seçeneklerini destekler. Dark10, Medium2 ve diğer önceden tanımlı tablo stilleri gibi profesyonel biçimlendirmeleri anında uygulayabilirsiniz. Sadece SetStyle metodunu kullanın veya tabloyu oluştururken tableStyle parametresini belirtin.
Adlandırılmış tablolarda filtreleri göstermek veya gizlemek mümkün mü?
Kesinlikle! IronXL, adlandırılmış tablolarda filtre görünürlüğünü kontrol etmenizi sağlar. ShowFilter özelliğini true veya false olarak ayarlayabilir veya tabloyu oluştururken showFilter parametresini direkt belirtebilirsiniz.
Adlandırılmış bir tablo oluşturmak için gerekli parametreler nelerdir?
IronXL'deki AddNamedTable metodu, iki temel parametre gerektirir: tablo ismi (bir dize olarak) ve tablo alanını tanımlayan aralık nesnesi. İsteğe bağlı parametreler arasında showFilter (boolean) ve tableStyle (TableStyles numaralandırmasından) bulunur.
Aynı çalışma sayfasında birden fazla stillendirilmiş adlandırılmış tablo oluşturabilir miyim?
Evet, IronXL, aynı çalışma sayfasında farklı stillerde birden fazla adlandırılmış tablo oluşturmanıza izin verir. Her tablo, kendi benzersiz ismi, aralığı, stili ve filtre ayarlarına sahip olabilir, bu da tek bir Excel dosyası içinde farklı veri setlerini düzenlemek için mükemmeldir.

