IronXL 教程 在 C# 中打开 Excel 文件 C# Write to Excel [Without Using Interop] Code Example Tutorial Curtis Chau 已更新:八月 17, 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 This article was translated from English: Does it need improvement? Translated View the article in English Follow step-by-step examples of how to create, open, and save Excel files with C#, and apply basic operations like getting sum, average, count, and more. IronXL.Excel is a stand-alone .NET software library for reading a wide range of spreadsheet formats. It does not require Microsoft Excel to be installed, nor depends on Interop. Quickstart: Create, Write & Save Excel in a Snap Ready to generate Excel files in under a minute? This example uses IronXL to create a workbook, write a value to a cell, and save the file—all with minimal fuss and zero reliance on Interop. It's the fastest way to get started with Excel file operations in C#. Get started making PDFs with NuGet now: Install IronXL with NuGet Package Manager PM > Install-Package IronXL.Excel Copy and run this code snippet. var workbook = IronXL.WorkBook.Create(IronXL.ExcelFileFormat.XLSX); workbook.CreateWorkSheet("Data")["A1"].Value = "Fast Start"; workbook.SaveAs("quick.xlsx"); Deploy to test on your live environment Start using IronXL in your project today with a free trial Free 30 day Trial Minimal Workflow (5 steps) Download the Write Excel C# Library Create and open a new CSV or XML Excel file as an Excel workbook Save and export your Excel workbook Apply Advanced Operations in your multiple Excel worksheets Integrate with Excel Database Overview Use IronXL to Open and Write Excel Files Open, write, save, and customize Excel files with the easy-to-use IronXL C# library. Download a sample project from GitHub or use your own, and follow the tutorial. Install the IronXL Excel Library from NuGet or the DLL download Use the WorkBook.Load method to read any XLS, XLSX, or CSV document. Get Cell values using intuitive syntax: sheet["A11"].DecimalValue In this tutorial, we will walk you through: Installing IronXL.Excel: how to install IronXL.Excel to an existing project. Basic Operations: basic operation steps with Excel to Create or Open workbook, select sheet, select cell, and save the workbook. Advanced Sheet Operations: how to utilize different manipulation capabilities like adding headers or footers, mathematical operations, and other features. Open an Excel File: Quick Code :path=/static-assets/excel/content-code-examples/tutorials/csharp-open-write-excel-file-1.cs using IronXL; WorkBook workBook = WorkBook.Load("test.xlsx"); WorkSheet workSheet = workBook.DefaultWorkSheet; IronXL.Range range = workSheet["A2:A8"]; decimal total = 0; // iterate over range of cells foreach (var cell in range) { Console.WriteLine("Cell {0} has value '{1}'", cell.RowIndex, cell.Value); if (cell.IsNumeric) { // Get decimal value to avoid floating numbers precision issue total += cell.DecimalValue; } } // Check formula evaluation if (workSheet["A11"].DecimalValue == total) { Console.WriteLine("Basic Test Passed"); } Imports IronXL Private workBook As WorkBook = WorkBook.Load("test.xlsx") Private workSheet As WorkSheet = workBook.DefaultWorkSheet Private range As IronXL.Range = workSheet("A2:A8") Private total As Decimal = 0 ' iterate over range of cells For Each cell In range Console.WriteLine("Cell {0} has value '{1}'", cell.RowIndex, cell.Value) If cell.IsNumeric Then ' Get decimal value to avoid floating numbers precision issue total += cell.DecimalValue End If Next cell ' Check formula evaluation If workSheet("A11").DecimalValue = total Then Console.WriteLine("Basic Test Passed") End If $vbLabelText $csharpLabel Write and Save Changes to the Excel File: Quick Code :path=/static-assets/excel/content-code-examples/tutorials/csharp-open-write-excel-file-2.cs workSheet["B1"].Value = 11.54; // Save Changes workBook.SaveAs("test.xlsx"); workSheet("B1").Value = 11.54 ' Save Changes workBook.SaveAs("test.xlsx") $vbLabelText $csharpLabel Step 1 1. Install the IronXL C# Library FREE 今天在您的项目中使用 IronXL,免费试用。 第一步: 免费开始 IronXL.Excel provides a flexible and powerful library for opening, reading, editing, and saving Excel files in .NET. It can be installed and used on all of the .NET project types, like Windows applications, ASP.NET MVC, and .NET Core Application. Install the Excel Library to your Visual Studio Project with NuGet The first step will be to install IronXL.Excel. To add the IronXL.Excel library to the project, we have two ways: NuGet Package Manager or NuGet Package Manager Console. To add IronXL.Excel library to our project using NuGet, we can do it using a visualized interface, NuGet Package Manager: Using mouse -> right-click on project name -> Select manage NuGet Package From the browse tab -> search for IronXL.Excel -> Install And we are done Install Using NuGet Package Manager Console From tools -> NuGet Package Manager -> Package Manager Console Run command Install-Package IronXL.Excel Manually Install with the DLL You may also choose to manually install the DLL to your project or to your global assembly cache. How To Tutorials 2. Basic Operations: Create, Open, Save 2.1. Sample Project: HelloWorld Console Application Create a HelloWorld Project in Visual Studio. Open Visual Studio Choose Create New Project Choose Console App (.NET framework) Give the sample the name “HelloWorld” and click create Now the console application is created Add IronXL.Excel to your project -> click install Add code to read the first cell in the first sheet from an Excel file and print it using IronXL; var workbook = WorkBook.Load("example.xlsx"); var sheet = workbook.DefaultWorkSheet; Console.WriteLine(sheet["A1"].Text); using IronXL; var workbook = WorkBook.Load("example.xlsx"); var sheet = workbook.DefaultWorkSheet; Console.WriteLine(sheet["A1"].Text); Imports IronXL Private workbook = WorkBook.Load("example.xlsx") Private sheet = workbook.DefaultWorkSheet Console.WriteLine(sheet("A1").Text) $vbLabelText $csharpLabel ... Further Reading To learn more about working with IronXL, you may wish to look at other tutorials within this section and also the examples on our homepage, which most developers find sufficient to get started. Our API Reference contains specific references to the WorkBook class. 常见问题解答 如何在C#中打开Excel文件而不使用Interop? 您可以使用 IronXL 的 WorkBook.Load 方法在 C# 中打开 XLS、XLSX 或 CSV 文件,而不需要 Microsoft Excel 或 Interop。 在 C# 中将数据写入 Excel 文件的步骤是什么? 要在 C# 中将数据写入 Excel 文件,可以使用 IronXL 创建工作簿和工作表,使用 worksheet["A1"].Value = "Your Value" 在特定单元格设置值,并使用 SaveAs 方法保存工作簿。 我如何使用 IronXL 操作 Excel 表格? 使用 IronXL,您可以添加、重命名或删除工作表,设置页眉和页脚,并直接对电子表格数据进行数学计算。 是否可以使用 C# 从 Excel 文件读取单元格值? 是的,使用 IronXL,可以使用类似 sheet["A1"].Text 的语法读取单元格值,以从 Excel 文件中的特定单元格提取文本。 如何在 .NET 项目中安装 IronXL? 您可以通过在 NuGet 包管理器搜索 IronXL.Excel 或使用包管理器控制台命令 Install-Package IronXL.Excel 在您的 .NET 项目中安装 IronXL。 IronXL 可以用于 ASP.NET MVC 项目吗? 是的,IronXL 兼容 ASP.NET MVC 项目,允许您在 Web 应用程序中处理 Excel 文件操作。 IronXL 支持哪些 Excel 操作的文件格式? IronXL 支持读取和写入 Excel 格式,比如 XLS、XLSX 和 CSV,实现了 C# 应用程序中灵活的数据处理。 在哪里可以找到使用 IronXL 的代码示例? 在 IronXL 网站上的教程和 GitHub 上提供的示例项目中可以找到使用 IronXL 的代码示例。 使用 IronXL 操作 Excel 文件有哪些优点? IronXL 允许开发者在 C# 中管理 Excel 文件,而无需 Microsoft Excel 或 Interop,提供了简便的 API 用于创建、读取和编辑 Excel 文档。 Curtis Chau 立即与工程团队聊天 技术作家 Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。 准备开始了吗? Nuget 下载 1,686,155 | 版本: 2025.11 刚刚发布 免费 NuGet 下载 总下载量:1,686,155 查看许可证