IRONSOFTWAREHOME
在C#中掌握Excel聚合函数
using IronXL;
using System.Linq;

WorkBook workBook = WorkBook.Load("sample.xls");
WorkSheet workSheet = workBook.WorkSheets.First();

// Get range from worksheet
var range = workSheet["A1:A8"];

// Apply sum of all numeric cells within the range
decimal sum = range.Sum();

// Apply average value of all numeric cells within the range
decimal avg = range.Avg();

// Identify maximum value of all numeric cells within the range
decimal max = range.Max();

// Identify minimum value of all numeric cells within the range
decimal min = range.Min();
Imports IronXL
Imports System.Linq

Dim workBook As WorkBook = WorkBook.Load("sample.xls")
Dim workSheet As WorkSheet = workBook.WorkSheets.First()

' Get range from worksheet
Dim range = workSheet("A1:A8")

' Apply sum of all numeric cells within the range
Dim sum As Decimal = range.Sum()

' Apply average value of all numeric cells within the range
Dim avg As Decimal = range.Avg()

' Identify maximum value of all numeric cells within the range
Dim max As Decimal = range.Max()

' Identify minimum value of all numeric cells within the range
Dim min As Decimal = range.Min()
NuGet Download
PM > Install-Package IronXL.Excel
在C#中掌握Excel聚合函数

在C#中掌握Excel聚合函数

上面的代码示例展示了如何轻松地从 Excel 电子表格中的一系列单元格中获取聚合值。 但是请注意,任何非数字单元格都将被忽略。

Sum

方法Sum()返回选定单元格范围的总和。

Average

方法Average()返回选定单元格范围的平均值。

Minimum

方法Min()返回选定单元格范围中的最小数。

Maximum

方法Max()返回选定单元格范围中的最大数。

为了更灵活地处理数据,上述函数也可以应用于单行/多行或多列。 了解更多关于选择行和列的信息

使用 C# 探索 Excel 中的数学函数
在 GitHub 上查看

准备开始了吗?

Nuget Downloads 2,237,574版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户