在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();
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,362,812版本:2026.11刚刚发布