与其他组件比较 IronXL 和 ClosedXML 的比较 Curtis Chau 已更新:七月 28, 2025 Download IronXL NuGet 下载 DLL 下载 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article Today's software applications require the ability to create databases and generate reports using Excel files. There are many libraries available today that allow users to do this without the need for Microsoft Excel. In this article, we are going to discuss and compare how to work with Microsoft Excel documents programmatically in C# .NET technologies using two of the most popular libraries, IronXL and ClosedXML, for reading, manipulating, and writing Excel reports. IronXL and ClosedXML both provide methods to create, edit, and read Excel documents in the .NET framework. The next question is to decide which C# Excel library is best suited to your project. This article will help you decide on the best option for your applications. Let's look first at what both libraries have to offer, and then move on to the comparison itself. The IronXL Library IronXL is a .NET library that facilitates reading and editing Microsoft Excel documents with C#. IronXL.Excel is a standalone .NET software library for reading a wide range of spreadsheet formats. It does not require Microsoft Excel to be installed, nor does it depend on Interop. IronXL is an intuitive C# API that allows you to read, edit, and create Excel spreadsheet files in .NET with lightning-fast performance. IronXL fully supports .NET Core, .NET Framework, Xamarin, Mobile, Linux, macOS, and Azure. IronXL is a leading .NET Core and .NET Framework Excel spreadsheet library for C#. IronXL Feature Set Load, read, and edit data from XLS/XLSX/CSV/TSV Saving and exporting to XLS/XLSX/CSV/TSV/JSON System.Data Objects: Work with Excel Spreadsheets as System.Data.DataSet and System.Data.DataTable objects. Formulas: Work with Excel formulas, recalculated every time a sheet is edited. Ranges: Easy to use WorkSheet ["A1:B10"] syntax. Combine and create ranges intuitively. Sorting: Sort ranges, columns, and rows. Styling: Cell visual styles, font, size, background pattern, border, alignment, and number formats. More Features of IronXL can be explored using this link. ClosedXML ClosedXML is a .NET library for reading, manipulating, and writing Excel 2007+ (.xlsx, .xlsm) files. It aims to provide an intuitive and user-friendly interface for dealing with the underlying OpenXML Library. The .xlsx is a file extension for an OpenXML underlying API spreadsheet file format used by Microsoft Excel. The .xlsm files support macros. The .xltm are macro-enabled template files. The .xls format is a proprietary binary format, while .xlsx is based on Office OpenXML format. ClosedXML is a .NET library for report generation in Microsoft Excel without requiring Excel to be installed on the machine that's running the code. ClosedXML Features ClosedXML has a user-friendly interface with extensive API functions to handle creation and extraction of content in Excel. With these API calls and pull requests, you can modify every little detail in an Excel sheet or workbook. All the features are listed below: Formulas Validation Hyper-Links Protection (Sheet and Cell level) Conditional Formatting Freeze Panes Tables Ranges Styling Page Setup (Printing) Auto-Filters Comments The rest of this article continues as follows: Create a Console Application IronXL C# Library Installation ClosedXML Installation Create and Save a new Excel Workbook and Sheet Read Excel File Working with Excel Formulas Licensing Summary and Conclusion 1. Create a Console Application Use the following steps to create a Console Application: Start the Visual Studio 2022 IDE. Click on "Create a new project." On the "Create a new project" page, select C# in the language dropdown list, Windows from the Platforms list, and Console from the Project types list. Select Console App (.NET Framework) from the project templates displayed. Create a Project Click Next. Name the project "DemoApp" and Click Next. DemoApp Project In the Additional Information screen, specify the Framework version you would like to use. We will use .NET Framework 6.0 in this example. .NET Framework 6.0 Click Create to complete the process. Now, the project is created and we are almost ready to test the libraries. However, we still need to install and integrate them into our project. Let's install IronXL first. 2. IronXL C# Library Installation You can download and install the IronXL library using the following methods: Using Visual Studio with NuGet packages. Manually installing the DLL. Let's take a closer look at each one. 2.1. Using Visual Studio with NuGet Packages Visual Studio provides the NuGet Package Manager to install NuGet packages in your projects. You can access it through the Project Menu, or by right-clicking your project in the Solution Explorer. Package Manager Next, from the Browse tab > search for IronXL.Excel > Install IronXL NuGet Install And we are done. 2.2. Manually Installing the DLL Another way to download and install the IronXL C# Library is to make use of the following steps to install the IronXL NuGet package through the Developer Command Prompt. Open the Developer Command Prompt — usually found in the Visual Studio folder. Type the following command: Install-Package IronXL.Excel Press Enter. This will download and install the package. Reload your Visual Studio project and begin using it. 2.3. Add Necessary Using Directives In Solution Explorer, right-click the Program.cs file and then click View Code. Add the following using directives to the top of the code file: using IronXL; using IronXL; Imports IronXL $vbLabelText $csharpLabel All done! IronXL is downloaded, installed, and ready to use. However, before that, we should install ClosedXML. 3. ClosedXML Installation To install the ClosedXML package, you can directly download it from NuGet or from NuGet Package Manager/Console in the project. For directly installing ClosedXML, click on this link. 3.1. Using the NuGet Package Manager/Console Open the NuGet Package Manager from project solution explorer, browse for ClosedXML, and click install. ClosedXML NuGet Install Or: Open the Developer Command Prompt — usually found in the Visual Studio folder. Type the following command: Install-Package ClosedXML Press Enter. This will download and install the package. Reload your Visual Studio project and begin using it. 3.2. Add Necessary Using Directives In Solution Explorer, right-click the Program.cs file and then click View Code. Add the following using directives to the top of the code file: using ClosedXML.Excel; using ClosedXML.Excel; Imports ClosedXML.Excel $vbLabelText $csharpLabel 4. Create and Save a New Excel Workbook and Sheets A workbook is an Excel file containing multiple worksheets with rows and columns. Both libraries provide the facility to create a new Excel workbook and sheets. Let's have a look at the code step-by-step. 4.1. New Excel Workbook and Sheets using IronXL It could not be any easier to create a new Excel Workbook using IronXL. It takes just one line of code. Yes, really. Add the following code to your static void main function in the Program.cs file: // Create a new Excel workbook using IronXL WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX); // Create a new Excel workbook using IronXL WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX); ' Create a new Excel workbook using IronXL Dim workbook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX) $vbLabelText $csharpLabel Both XLS (older Excel file version) and XLSX (current and newer file version) file formats can be created with IronXL. And, it's even simpler to create a default Worksheet: // Create a new worksheet within the workbook var worksheet = workbook.CreateWorkSheet("IronXL Features"); // Create a new worksheet within the workbook var worksheet = workbook.CreateWorkSheet("IronXL Features"); ' Create a new worksheet within the workbook Dim worksheet = workbook.CreateWorkSheet("IronXL Features") $vbLabelText $csharpLabel You can now use the worksheet variable to set cell values and do almost everything an Excel file can do. // 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; // 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; ' 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 $vbLabelText $csharpLabel Save the Excel file: // Save the spreadsheet workbook.SaveAs("NewExcelFile.xlsx"); // Save the spreadsheet workbook.SaveAs("NewExcelFile.xlsx"); ' Save the spreadsheet workbook.SaveAs("NewExcelFile.xlsx") $vbLabelText $csharpLabel The output file looks as follows: NewExcelFile output 4.2. New Excel Workbook and Sheets using ClosedXML You can also create excel files (.xlsx, .xlsm) easily using ClosedXML. The following code is a typical example which serves to generate a simple Excel file and save it. You can add a new sample sheet to your workbook and assign values to cells in your Excel application. // Create a new empty Excel file var workbook = new XLWorkbook(); // Create a new worksheet and set cell A1 value to 'Hello world!' var worksheet = workbook.Worksheets.Add("ClosedXML Features"); worksheet.Cell("A1").Value = "Hello world!"; // Save to XLSX file workbook.SaveAs("Spreadsheet.xlsx"); // Create a new empty Excel file var workbook = new XLWorkbook(); // Create a new worksheet and set cell A1 value to 'Hello world!' var worksheet = workbook.Worksheets.Add("ClosedXML Features"); worksheet.Cell("A1").Value = "Hello world!"; // Save to XLSX file workbook.SaveAs("Spreadsheet.xlsx"); ' Create a new empty Excel file Dim workbook = New XLWorkbook() ' Create a new worksheet and set cell A1 value to 'Hello world!' Dim worksheet = workbook.Worksheets.Add("ClosedXML Features") worksheet.Cell("A1").Value = "Hello world!" ' Save to XLSX file workbook.SaveAs("Spreadsheet.xlsx") $vbLabelText $csharpLabel The output file looks as follows: Spreadsheet File Output 5. Read Excel File (Import Excel File) Both libraries can open and read existing Excel documents. Let's have a look at the sample code. 5.1. Read Excel Files using IronXL The IronXL WorkBook class represents an Excel sheet. To open an Excel file using C#, we use WorkBook.Load and specify the path of the file (.xlsx). The following one-line code is used to open the file for reading: // Load WorkBook var workbook = WorkBook.Load(@"Spreadsheets\\sample.xlsx"); // Load WorkBook var workbook = WorkBook.Load(@"Spreadsheets\\sample.xlsx"); ' Load WorkBook Dim workbook = WorkBook.Load("Spreadsheets\\sample.xlsx") $vbLabelText $csharpLabel Each WorkBook can have multiple worksheets in the Excel document. If the workbook contains multiple worksheets, retrieve them by name as follows: // Open Sheet for reading var worksheet = workbook.GetWorkSheet("sheetnamegoeshere"); // Open Sheet for reading var worksheet = workbook.GetWorkSheet("sheetnamegoeshere"); ' Open Sheet for reading Dim worksheet = workbook.GetWorkSheet("sheetnamegoeshere") $vbLabelText $csharpLabel Code for reading the cell values: // Read from ranges of cells elegantly foreach (var cell in worksheet["A2:A10"]) { Console.WriteLine("Cell {0} has value '{1}'", cell.AddressString, cell.Text); } // Read from ranges of cells elegantly foreach (var cell in worksheet["A2:A10"]) { Console.WriteLine("Cell {0} has value '{1}'", cell.AddressString, cell.Text); } ' Read from ranges of cells elegantly For Each cell In worksheet("A2:A10") Console.WriteLine("Cell {0} has value '{1}'", cell.AddressString, cell.Text) Next cell $vbLabelText $csharpLabel 5.2. Read Excel Files using ClosedXML ClosedXML allows reading of previously created files from your C# application. You can import an excel file using the following code. // Import Excel file from file's path var workbook = new XLWorkbook("SimpleTemplate.xlsx"); // Read worksheet from workbook using sheet number var worksheet1 = workbook.Worksheet(1); // Read cell value from the first sheet var data = worksheet1.Cell("A1").GetValue<string>(); // Display on screen Console.WriteLine(data); // Import Excel file from file's path var workbook = new XLWorkbook("SimpleTemplate.xlsx"); // Read worksheet from workbook using sheet number var worksheet1 = workbook.Worksheet(1); // Read cell value from the first sheet var data = worksheet1.Cell("A1").GetValue<string>(); // Display on screen Console.WriteLine(data); ' Import Excel file from file's path Dim workbook = New XLWorkbook("SimpleTemplate.xlsx") ' Read worksheet from workbook using sheet number Dim worksheet1 = workbook.Worksheet(1) ' Read cell value from the first sheet Dim data = worksheet1.Cell("A1").GetValue(Of String)() ' Display on screen Console.WriteLine(data) $vbLabelText $csharpLabel 6. Working with Excel Formulas Excel formulas are one of the most important features of working with Excel. Both libraries have a powerful formula calculation engine. They provide the facility to work with formulas and easily apply them to cells. 6.1. Working with Excel Formulas using IronXL After loading the workbook and worksheet, the following code sample can be used to either make changes to formulas, or be applied to specific cells. The code is as follows: // Set formulas worksheet["A1"].Formula = "=Sum(B8:C12)"; worksheet["B8"].Formula = "=C9/C11"; worksheet["G30"].Formula = "=Max(C3:C7)"; // Force recalculating all formula values in all sheets workbook.EvaluateAll(); // Set formulas worksheet["A1"].Formula = "=Sum(B8:C12)"; worksheet["B8"].Formula = "=C9/C11"; worksheet["G30"].Formula = "=Max(C3:C7)"; // Force recalculating all formula values in all sheets workbook.EvaluateAll(); ' Set formulas worksheet("A1").Formula = "=Sum(B8:C12)" worksheet("B8").Formula = "=C9/C11" worksheet("G30").Formula = "=Max(C3:C7)" ' Force recalculating all formula values in all sheets workbook.EvaluateAll() $vbLabelText $csharpLabel You can also retrieve formulas and their values: // Get the formula's calculated value e.g. "52" string formulaValue = worksheet["G30"].Value; // Get the formula as a string e.g. "Max(C3:C7)" string formulaString = worksheet["G30"].Formula; // Save your changes with updated formulas and calculated values workbook.Save(); // Get the formula's calculated value e.g. "52" string formulaValue = worksheet["G30"].Value; // Get the formula as a string e.g. "Max(C3:C7)" string formulaString = worksheet["G30"].Formula; // Save your changes with updated formulas and calculated values workbook.Save(); ' Get the formula's calculated value e.g. "52" Dim formulaValue As String = worksheet("G30").Value ' Get the formula as a string e.g. "Max(C3:C7)" Dim formulaString As String = worksheet("G30").Formula ' Save your changes with updated formulas and calculated values workbook.Save() $vbLabelText $csharpLabel 6.2. Working with Excel Formulas using ClosedXML ClosedXML does not support all formulas and you'll probably get a nasty error if the formula isn't supported or if there's an error in the formula. Please test your formulas before going to production. Let's have a look at how to use them. // Set formulas worksheet.Cell("A1").Value = "Hello World!"; worksheet.Cell("A2").FormulaA1 = "=MID(A1, 7, 5)"; // You can use Evaluate function to directly calculate formula var sum = worksheet.Evaluate("SUM(B1:B7)"); // Force recalculation worksheet.RecalculateAllFormulas(); // Save Excel file workbook.SaveAs("Formula Calculation.xlsx"); // Set formulas worksheet.Cell("A1").Value = "Hello World!"; worksheet.Cell("A2").FormulaA1 = "=MID(A1, 7, 5)"; // You can use Evaluate function to directly calculate formula var sum = worksheet.Evaluate("SUM(B1:B7)"); // Force recalculation worksheet.RecalculateAllFormulas(); // Save Excel file workbook.SaveAs("Formula Calculation.xlsx"); ' Set formulas worksheet.Cell("A1").Value = "Hello World!" worksheet.Cell("A2").FormulaA1 = "=MID(A1, 7, 5)" ' You can use Evaluate function to directly calculate formula Dim sum = worksheet.Evaluate("SUM(B1:B7)") ' Force recalculation worksheet.RecalculateAllFormulas() ' Save Excel file workbook.SaveAs("Formula Calculation.xlsx") $vbLabelText $csharpLabel The property FormulaA1 is with reference to A1 cell. If you are referencing another cell, you must add it to the Formula property. E.g., FormulaC2. 7. Licensing IronXL is an openly commercial C# Excel library. It is free for development and can always be licensed for commercial deployment. Licenses are available for single-project use, single developers, agencies, and global corporations as well as SaaS and OEM redistribution. All licenses include a 30-day money-back guarantee, one year of product support and updates, validity for dev/staging/production, and also a permanent license (one-time purchase). The lite package starts from $799. IronXL License Packages For ClosedXML, applications using this DLL file do not require a separate license either for single-use or commercial use. In order for any solution to work with ClosedXML, just install the publicly available NuGet package "ClosedXML". ClosedXML is licensed under the MIT License. MIT License is a short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code. ClosedXML License 8. Summary and Conclusion Summary IronXL is a complete library offering everything you need to manipulate an Excel file. IronXL allows developers to read, generate, and edit Excel (and other Spreadsheet files) in .NET applications & websites. It provides a fast and natural approach to work with Excel and other Spreadsheet files in C#. ClosedXML is a .NET library for reading and writing Excel files, which makes it easier for developers to create Excel 2007+ files. It provides a nice object-oriented way to manipulate the files (similar to VBA) without dealing with the hassles of XML Documents. It can be used by any .NET language like C# and Visual Basic (VB). It provides features of OpenXML but still some are not implemented. E.g., Macros, Embedding, and Charts. Conclusion IronXL is also helpful in other Excel operations like cell data formats, sorting, cell styling. It can also work with Excel Spreadsheets as System.Data.DataSet and System.Data.DataTable. It supports console, web server, and desktop-based applications. It is also supported on all OS platforms. ClosedXML is a lightweight library for reading, manipulating, and writing Excel applications using OpenXML API which is fast and easier to implement. It helps in all major Excel operations like Page Setup, Freeze Panes, Hyperlinks, Tables, and Conditional Formatting. It has no overhead or low performance issues. In comparison, IronXL and ClosedXML both are fast and accurate when it comes to Excel spreadsheets. They do not need Microsoft Office installation or license when it comes to creating Excel reports. However, IronXL has an advantage over ClosedXML as ClosedXML is not thread-safe. IronXL is easy to use and provides the facility to convert other formats to XLSX, and also from XLSX to other formats such as CSV and HTML. ClosedXML doesn't allow this conversion. This interconversion allows users the flexibility to work with other file formats with ease. Now you can get five Iron products for the price of just two in the lite package for 1 developer($suitePrice) and unlimited for $unlimitedSuitePrice and save up to 60%. 请注意ClosedXML is a registered trademark of its respective owner. This site is not affiliated with, endorsed by, or sponsored by ClosedXML. All product names, logos, and brands are property of their respective owners. Comparisons are for informational purposes only and reflect publicly available information at the time of writing. 常见问题解答 如何在 C# 中读取 Excel 文件而不使用 Interop? 要在 C# 中读取 Excel 文件而不使用 Interop,您可以使用像 IronXL 或 ClosedXML 这样的库。这些库不需要安装 Microsoft Excel,并提供用于编程读取和处理 Excel 文件的方法。 使用 IronXL 操作 Excel 文件有什么好处? IronXL 提供用户友好的 API,支持多种电子表格格式,并提供排序、样式和公式处理等操作。它也是线程安全的且允许导出到多种格式,使其成为操作 Excel 文件的多功能工具。 IronXL 能处理 Excel 公式吗? 是的,IronXL 可以处理 Excel 公式。它允许您在 Excel 文件中创建、评估和处理公式,为复杂的电子表格操作提供强大的功能。 IronXL 支持哪些平台? IronXL 支持多个平台,包括 .NET Framework, .NET Core, Xamarin 和 Azure,为在不同环境下工作的开发者提供了灵活的选择。 如何使用 C# 将 Excel 文件转换为 HTML? 要使用 C# 将 Excel 文件转换为 HTML,您可以使用 IronXL。它提供方法将 Excel 文件导出为 HTML 格式,方便在网上分享和展示电子表格数据。 在格式支持方面,IronXL 和 ClosedXML 有什么区别? IronXL 支持多种格式,包括 XLS, XLSX, CSV, TSV 和 JSON,并允许在这些格式之间进行转换。ClosedXML 主要处理使用 OpenXML 格式的 Excel 2007+(.xlsx, .xlsm)文件。 如何在 C# 项目中安装 IronXL? 您可以使用 Visual Studio 的 NuGet 包管理器,通过命令 Install-Package IronXL.Excel 安装 IronXL,或手动将 DLL 添加到您的项目中。 在商业项目中使用 IronXL 有任何许可证要求吗? 是的,IronXL 在商业项目中部署需要商业许可证。它提供多种许可选项,包括单项目、开发者、代理商和企业许可证,并提供 30 天退款保证。 Curtis Chau 立即与工程团队聊天 技术作家 Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。 相关文章 已更新六月 22, 2025 C# 开发人员使用 IronXL 的 Zip 存档教程 在本教程中,我们将探讨如何在C#中创建ZIP文件、从压缩文件中提取数据以及操作ZIP档案,使用相对路径。 阅读更多 已更新七月 28, 2025 比较三个开源 C# Excel 库 本文将探讨三个 C# 开源 Excel 库,旨在简化 .NET 环境中的 Excel 文件操作 阅读更多 已更新八月 4, 2025 EPPlus 读取 Excel 到 DataTable C#(IronXL 教程) EPPlus 是一个强大的开源库,用于在 C# 中创建和操作 Excel 文件。它提供了一个简单直观的 API,使开发人员能够以编程方式生成、读取和修改 Excel 电子表格。 阅读更多 IronXL 和 FastExcel 的比较 - .NETIronXL 和 GrapeCity Excel 查看...
已更新八月 4, 2025 EPPlus 读取 Excel 到 DataTable C#(IronXL 教程) EPPlus 是一个强大的开源库,用于在 C# 中创建和操作 Excel 文件。它提供了一个简单直观的 API,使开发人员能够以编程方式生成、读取和修改 Excel 电子表格。 阅读更多