C#을 사용하여 Excel에 이름 있는 테이블을 추가하는 방법 | IronXL

C#을 사용하여 Excel에 네임드 표 추가하기

This article was translated from English: Does it need improvement?
Translated
View the article in English

Excel에서 명명된 테이블을 추가하려면 C#을 사용하여 IronXL의 AddNamedTable 메서드를 테이블 이름, 범위 및 선택적 스타일링의 매개변수와 함께 사용하세요. 이는 단일 메서드 호출로 구조화된 데이터 관리를 가능하게 합니다.

네임드 표는 Excel Table이라고도 알려져 있으며, 이름이 지정되고 추가 기능과 속성이 연결된 특정 유형의 범위를 나타냅니다. 네임드 표는 향상된 데이터 조직 기능, 자동 포맷팅, 내장 필터링 및 Excel 공식과의 원활한 통합을 제공하여 Excel 자동화 워크플로에서 구조화된 데이터 세트를 관리하는 데 필수적입니다.

빠른 시작: 한 줄로 표 작성 및 이름 지정하기

이 예제는 IronXL을 사용하여 워크시트에 네임드 표를 얼마나 쉽게 추가할 수 있는지 보여줍니다. 이름, 범위, 필터 가시성 및 스타일을 명확한 단일 메서드 호출로 모두 정의하세요.

  1. NuGet 패키지 관리자를 사용하여 https://www.nuget.org/packages/IronXl.Excel 설치하기

    PM > Install-Package IronXl.Excel
  2. 다음 코드 조각을 복사하여 실행하세요.

    var table = workSheet.AddNamedTable("MyTable", workSheet.GetRange("A1:B5"), showFilter: true, tableStyle: IronXl.Styles.TableStyles.Medium2);
  3. 실제 운영 환경에서 테스트할 수 있도록 배포하세요.

    무료 체험판으로 오늘 프로젝트에서 IronXL 사용 시작하기

    arrow pointer


내 Excel 워크시트에 네임드 표를 어떻게 추가하나요?

명명된 테이블을 추가하려면 AddNamedTable 메서드를 사용하세요. 메서드는 표의 이름과 범위 객체를 문자열로 요구합니다. 표 스타일과 필터 표시 여부를 선택할 수도 있습니다. 이 기능은 구조화된 데이터가 적절하게 조직되어야 하는 DataSetDataTable 가져오기 작업 시 특히 유용합니다.

// 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");
$vbLabelText   $csharpLabel

명명된 테이블은 TableStyles 열거형을 통해 다양한 스타일링 옵션을 지원합니다. 셀 스타일링 및 테두리 정렬과 같은 다른 포맷팅 기능을 보완하여 전문적인 포맷팅을 즉각적으로 적용할 수 있습니다. 여기 다양한 표 스타일 응용을 보여주는 예제가 있습니다:

// 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");
$vbLabelText   $csharpLabel
서식이 지정된 헤더가 있고 샘플 텍스트 데이터가 포함된 세 개의 열을 가진 네임드 표를 표시하는 엑셀 스프레드시트

내 워크시트에서 네임드 표를 어떻게 검색하나요?

워크시트의 모든 네임드 표를 반환하는 메서드는 무엇입니까?

GetNamedTableNames 메서드는 워크시트의 모든 명명된 테이블을 문자열 리스트로 반환합니다. 이것은 여러 표를 포함한 워크북을 다루거나 동적 데이터 구조를 가진 워크시트를 관리할 때 특히 유용합니다.

// 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);
}
$vbLabelText   $csharpLabel

특정 네임드 표에 이름으로 접근하려면 어떻게 해야 하나요?

워크시트에서 특정 명명된 테이블을 검색하려면 GetNamedTable 메서드를 사용하세요. 검색한 후, 다양한 속성에 접근하고 셀 범위 정렬이나 조건부 서식 적용과 같은 작업을 수행할 수 있습니다.

// 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);
$vbLabelText   $csharpLabel

표 데이터 작업하기

네임드 표는 강력한 데이터 조작 기능을 제공합니다. 표 데이터를 다루는 방법을 보여주는 포괄적인 예시입니다:

// 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");
$vbLabelText   $csharpLabel

다른 IronXL 기능과의 통합

네임드 표는 다른 IronXL 기능과 원활하게 작동합니다. 공식과 결합하여 동적 계산을 하거나 차트 생성 시 데이터 소스로 사용할 수 있습니다. 다양한 형식으로 내보내기 전에 데이터를 정리하기에도 뛰어납니다.

// 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");
$vbLabelText   $csharpLabel

IronXL은 네임드 범위도 추가할 수 있습니다. 자세한 내용을 보려면 네임드 범위 추가 방법을 참고하세요.

자주 묻는 질문

엑셀에서 이름이 지정된 테이블이란 무엇입니까?

Excel에서 이름이 지정된 테이블은 특정 유형의 범위로, 이름이 지정되어 있으며 추가적인 기능을 제공합니다. IronXL을 사용하면 C#으로 이러한 테이블을 프로그래밍 방식으로 생성할 수 있으며, 향상된 데이터 구성 기능, 자동 서식 지정, 내장 필터링 및 Excel 수식과의 원활한 통합 기능을 제공합니다.

C#을 사용하여 Excel 워크시트에 이름이 지정된 테이블을 추가하는 방법은 무엇입니까?

IronXL을 사용하여 명명된 테이블을 추가하려면 AddNamedTable 메서드를 사용합니다. 이 메서드는 문자열 형식의 테이블 이름과 범위 객체를 필요로 합니다. 선택적으로 테이블 스타일과 필터 표시 여부를 지정할 수 있습니다. 예를 들면 다음과 같습니다. workSheet.AddNamedTable("MyTable", workSheet.GetRange("A1:B5"), showFilter: true, tableStyle: IronXl.Styles.TableStyles.Medium2).

이름이 지정된 테이블에 사용자 지정 스타일을 적용할 수 있나요?

네, IronXL은 TableStyles 열거형을 통해 명명된 테이블에 다양한 스타일링 옵션을 지원합니다. Dark10, Medium2 및 기타 미리 정의된 테이블 스타일을 사용하여 전문적인 서식을 즉시 적용할 수 있습니다. SetStyle 메서드를 사용하거나 테이블을 생성할 때 tableStyle 매개변수를 지정하기만 하면 됩니다.

명명된 테이블에서 필터를 표시하거나 숨길 수 있습니까?

물론입니다! IronXL을 사용하면 명명된 테이블에서 필터 표시 여부를 제어할 수 있습니다. ShowFilter 속성을 true 또는 false로 설정하거나, AddNamedTable 메서드의 showFilter 매개변수를 사용하여 테이블을 생성할 때 직접 지정할 수 있습니다.

명명된 테이블을 생성하는 데 필요한 매개변수는 무엇입니까?

IronXL의 AddNamedTable 메서드는 두 가지 필수 매개변수를 필요로 합니다. 하나는 테이블 이름(문자열)이고, 다른 하나는 테이블 영역을 정의하는 범위 객체입니다. 선택적 매개변수로는 showFilter(부울)와 tableStyle(TableStyles 열거형에서 선택)이 있습니다.

같은 워크시트에 스타일이 지정된 여러 개의 이름 있는 표를 만들 수 있나요?

네, IronXL을 사용하면 동일한 워크시트에 서로 다른 스타일을 가진 여러 개의 이름 지정된 테이블을 만들 수 있습니다. 각 테이블은 고유한 이름, 범위, 스타일 및 필터 설정을 가질 수 있으므로 단일 Excel 파일 내에서 다양한 데이터 세트를 정리하는 데 적합합니다.

커티스 차우
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.

A PHP Error was encountered

Severity: Notice

Message: Undefined index: IronXl.Excel

Filename: helpers/counter_helper.php

Line Number: 85

Backtrace:

File: /var/www/ironpdf.com/application/helpers/counter_helper.php
Line: 85
Function: _error_handler

File: /var/www/ironpdf.com/application/views/main/sections/ready_to_started_202509.php
Line: 12
Function: getTotalDonwloadNumber

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 489
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Undefined index: IronXl.Excel

Filename: helpers/counter_helper.php

Line Number: 85

Backtrace:

File: /var/www/ironpdf.com/application/helpers/counter_helper.php
Line: 85
Function: _error_handler

File: /var/www/ironpdf.com/application/views/main/sections/ready_to_started_202509.php
Line: 19
Function: getTotalDonwloadNumber

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 489
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

시작할 준비 되셨나요?
Nuget 다운로드 1,890,100 | 버전: 2026.3 방금 출시되었습니다

A PHP Error was encountered

Severity: Notice

Message: Undefined index: IronXl.Excel

Filename: helpers/counter_helper.php

Line Number: 85

Backtrace:

File: /var/www/ironpdf.com/application/helpers/counter_helper.php
Line: 85
Function: _error_handler

File: /var/www/ironpdf.com/application/views/main/sections/still_scrolling_202512.php
Line: 17
Function: getTotalDonwloadNumber

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 71
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Undefined index: IronXl.Excel

Filename: helpers/counter_helper.php

Line Number: 85

Backtrace:

File: /var/www/ironpdf.com/application/helpers/counter_helper.php
Line: 85
Function: _error_handler

File: /var/www/ironpdf.com/application/views/main/sections/still_scrolling_202512.php
Line: 24
Function: getTotalDonwloadNumber

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 71
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

Still Scrolling Icon

아직도 스크롤하고 계신가요?

빠른 증거를 원하시나요? PM > Install-Package IronXl.Excel
샘플을 실행하세요 데이터가 스프레드시트로 변환되는 것을 지켜보세요.