Read data in Excel files using C#

Excel 分布表是存储和组织数据的常见格式,使其成为企业和个人的重要工具,无论您正在分析财务数据,创建报告,或操纵数据集,能够在您的 C# 应用程序中与 Excel 文件一起工作,都至关重要。

Aspose.Cells for .NET 是一個堅固的圖書館,簡化 Excel 檔案操作在 C#. 在這篇博客文章中,我們將探索如何在 .NET 應用程式中使用 C# 閱讀 Excel 檔案,提供一步一步指南,以幫助您開始。

内容表

C# API 阅读 Excel 文件 {# 图书馆阅读 Excel 文件}

To read data from Excel sheets, we will utilize Aspose.Cells 为 .NET. This feature-rich API allows you to create and manipulate Excel files effortlessly. You can download it from the 下载部分 or install it via 诺基亚.

PM> Install-Package Aspose.Cells

阅读 Excel 文件中的数据在 C#

在 Excel 文件中,数据存储在 单元格,每个单元格都以其名称(例如,A1,B3)或序列和列指数识别。 这些单元格的集合形成一个 工作表,而 Excel 文件可能包含一个或多个工作表。

下面是阅读 Excel 文件并在 C# 中提取数据的步骤:

  • Load the Excel file using the 工作簿 class.
  • Create an instance of the 工作表集 class and reference the worksheets using 工作簿 - 工作簿.
  • 通过收藏中的所有工作表:- Get a reference to each worksheet in a 工作表 object.
  • 在工作表中计算数据行和列。
  • 穿越行列,穿越柱子。
  • Read data from each cell using the [工作表. 细胞I、J 值 property.

下面是一个代码样本,表明如何在C#中阅读Excel文件:

在运行上面的代码样本后,控制台输出将显示从 Excel 文件中提取的数据:

Reading data in the worksheets of Excel file in C#

Reading an Excel File in C#

阅读一个特定的 Excel 表

如果您只需要在 Excel 文件中阅读一个特定的工作表,您可以遵循以下步骤:

  • Load the Excel file using the 工作簿 class.
  • Get a reference to the desired worksheet using [工作簿 - 工作簿指数).
  • 在工作表中计算数据行和列。
  • 穿越行列,穿越柱子。
  • Read data from each cell using the [工作表. 细胞I、J 值 property.

下面是从 C# 中的特定工作表中阅读数据的代码样本:

获取免费 API 阅读 Excel 数据

You can use Aspose.Cells for .NET to read Excel files without evaluation limitations by obtaining a 免费临时许可证.

结论

阅读 Excel 文件在 C# 使用 Aspose.Cells for .NET 是一个简单而高效的过程. 这个强大的 API 提供了一个全面的功能集,以处理所有 Excel 文件操作的各个方面在您的 .NET 应用程序. 无论您需要提取数据,格式表,或执行先进的任务, Aspose.Cells 使过程无缝,并帮助您实现与 Excel 相关的目标无缝。

Explore more features of Aspose.Cells for .NET through the 人们在说什么. If you have any questions, feel free to reach out via our 论坛.

其他资源

对于开发人员寻求实施解决方案,这里有一些额外的洞察力:

  • **如何使用 C# 阅读 Excel 表中的数据:这对于将 Excel 的数据集成到您的应用程序至关重要。
  • 如何在 ASP.NET 中阅读 Excel 文件使用 C#: 网页应用程序的详细方法。
  • .NET Core Excel Reader: 了解如何在 .NET 核心项目中使用此功能。
  • ** .NET Excel Reader**: 探索适合传统的 .Net 应用程序的定制方法。
  • ** .NET 阅读 Excel 文件**: 更广泛的技术概述,以处理 Excel 在 .net 环境中的文件。

More in this category