A Guide to Reading and Writing Excel Files in C
IronXL 소프트웨어 라이브러리를 사용하면 C# 및 기타 .NET 언어에서 Excel(XLS, XLSX 및 CSV) 파일을 읽고 만드는 것이 쉽습니다.
IronXL은 서버에 Excel Interop을 설치할 필요가 없습니다. IronXL은 Microsoft.Office.Interop.Excel 보다 빠르고 직관적인 API를 제공합니다.
IronXL은 다음 플랫폼에서 작동합니다:
- Windows 및 Azure for .NET Framework 4.6.2 이상
- Windows, Linux, MacOS 및 Azure for .NET Core 2 이상
- .NET 5, .NET 6, .NET 7, .NET 8, Mono, Maui, 그리고 Xamarin
IronXL 설치
Firstly install IronXL, using our NuGet package or by downloading the DLL. IronXL classes can be found in the IronXL namespace.
IronXL을 설치하는 가장 쉬운 방법은 Visual-Studio의 NuGet 패키지 관리자를 사용하는 것입니다: 패키지 이름은 IronXL.Excel입니다.
Install-Package IronXL.Excel
엑셀 문서 읽기
IronXL을 사용하면 몇 줄의 코드만으로 Excel 파일에서 데이터를 추출할 수 있습니다.
:path=/static-assets/excel/content-code-examples/get-started/get-started-1.cs
using IronXL;
// Supported spreadsheet formats for reading include: XLSX, XLS, CSV and TSV
WorkBook workBook = WorkBook.Load("data.xlsx");
WorkSheet workSheet = workBook.WorkSheets.First();
// Select cells easily in Excel notation and return the calculated value, date, text or formula
int cellValue = workSheet["A2"].IntValue;
// Read from Ranges of cells elegantly.
foreach (var cell in workSheet["A2:B10"])
{
Console.WriteLine("Cell {0} has value '{1}'", cell.AddressString, cell.Text);
}
Imports IronXL
' Supported spreadsheet formats for reading include: XLSX, XLS, CSV and TSV
Private workBook As WorkBook = WorkBook.Load("data.xlsx")
Private workSheet As WorkSheet = workBook.WorkSheets.First()
' Select cells easily in Excel notation and return the calculated value, date, text or formula
Private cellValue As Integer = workSheet("A2").IntValue
' Read from Ranges of cells elegantly.
For Each cell In workSheet("A2:B10")
Console.WriteLine("Cell {0} has value '{1}'", cell.AddressString, cell.Text)
Next cell
새 엑셀 문서 만들기
IronXL은 C# 또는 VB.NET을 사용하여 Excel 문서를 생성하는 빠르고 쉬운 인터페이스를 제공합니다.
:path=/static-assets/excel/content-code-examples/get-started/get-started-2.cs
using IronXL;
// Create new Excel WorkBook document.
WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLSX);
workBook.Metadata.Author = "IronXL";
// Add a blank WorkSheet
WorkSheet workSheet = workBook.CreateWorkSheet("main_sheet");
// Add data and styles to the new worksheet
workSheet["A1"].Value = "Hello World";
workSheet["A2"].Style.BottomBorder.SetColor("#ff6600");
workSheet["A2"].Style.BottomBorder.Type = IronXL.Styles.BorderType.Double;
// Save the excel file
workBook.SaveAs("NewExcelFile.xlsx");
Imports IronXL
' Create new Excel WorkBook document.
Private workBook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
workBook.Metadata.Author = "IronXL"
' Add a blank WorkSheet
Dim workSheet As WorkSheet = workBook.CreateWorkSheet("main_sheet")
' Add data and styles to the new worksheet
workSheet("A1").Value = "Hello World"
workSheet("A2").Style.BottomBorder.SetColor("#ff6600")
workSheet("A2").Style.BottomBorder.Type = IronXL.Styles.BorderType.Double
' Save the excel file
workBook.SaveAs("NewExcelFile.xlsx")
CSV, XLS, XLSX, JSON 또는 XML 형식으로 내보내기
IronXL은 또한 다양한 인기 있는 구조화 스프레드시트 형식으로 데이터를 저장하거나 내보낼 수 있습니다.
:path=/static-assets/excel/content-code-examples/get-started/get-started-3.cs
// Export to many formats with fluent saving
workSheet.SaveAs("NewExcelFile.xls");
workSheet.SaveAs("NewExcelFile.xlsx");
workSheet.SaveAsCsv("NewExcelFile.csv");
workSheet.SaveAsJson("NewExcelFile.json");
workSheet.SaveAsXml("NewExcelFile.xml");
' Export to many formats with fluent saving
workSheet.SaveAs("NewExcelFile.xls")
workSheet.SaveAs("NewExcelFile.xlsx")
workSheet.SaveAsCsv("NewExcelFile.csv")
workSheet.SaveAsJson("NewExcelFile.json")
workSheet.SaveAsXml("NewExcelFile.xml")
셀 및 범위 스타일링
IronXL.Range.Style 객체를 사용하여 Excel 셀 및 범위에 서식을 적용할 수 있습니다.
:path=/static-assets/excel/content-code-examples/get-started/get-started-4.cs
// Set cell's value and styles
workSheet["A1"].Value = "Hello World";
workSheet["A2"].Style.BottomBorder.SetColor("#ff6600");
workSheet["A2"].Style.BottomBorder.Type = IronXL.Styles.BorderType.Double;
' Set cell's value and styles
workSheet("A1").Value = "Hello World"
workSheet("A2").Style.BottomBorder.SetColor("#ff6600")
workSheet("A2").Style.BottomBorder.Type = IronXL.Styles.BorderType.Double
정렬 범위
IronXL을 사용하면 Range 객체를 사용하여 쉽게 Excel 셀 범위를 정렬할 수 있습니다.
:path=/static-assets/excel/content-code-examples/get-started/get-started-5.cs
using IronXL;
using Range = IronXL.Range;
WorkBook workBook = WorkBook.Load("test.xls");
WorkSheet workSheet = workBook.WorkSheets.First();
// This is how we get range from Excel worksheet
Range range = workSheet["A2:A8"];
// Sort the range in the sheet
range.SortAscending();
workBook.Save();
Imports IronXL
Dim workBook As WorkBook = WorkBook.Load("test.xls")
Dim workSheet As WorkSheet = workBook.WorkSheets.First()
' This is how we get range from Excel worksheet
Dim range As Range = workSheet("A2:A8")
' Sort the range in the sheet
range.SortAscending()
workBook.Save()
수식 편집
Excel 수식을 수정하는 것은 "=" 기호로 시작하는 값을 할당하는 것만큼 간단합니다. 수식은 즉시 계산됩니다.
:path=/static-assets/excel/content-code-examples/get-started/get-started-6.cs
// Set a formula
workSheet["A1"].Value = "=SUM(A2:A10)";
// Get the calculated value
decimal sum = workSheet["A1"].DecimalValue;
' Set a formula
workSheet("A1").Value = "=SUM(A2:A10)"
' Get the calculated value
Dim sum As Decimal = workSheet("A1").DecimalValue
왜 IronXL을 선택해야 하나요?
IronXL은 .NET에서 Excel 문서를 읽고 쓰기 위한 개발자 친화적인 API를 제공합니다. 서버에 Microsoft Excel 또는 Excel Interop을 설치할 필요 없이 작동하여 Excel 파일 처리가 빠르고 경량적이며 번거롭지 않습니다.
앞으로 나아가기
더 많은 기능과 기능 탐색을 위해 .NET API 참조를 검토할 것을 권장합니다. MSDN 문서와 유사한 형식으로 제공됩니다.

