Master Excel Aggregate Functions in C#
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
Master Excel Aggregate Functions in C#

Master Excel Aggregate Functions in C#

The code example above shows how to easily get aggregate values from a range of cells in an Excel spreadsheet. However, please note that any non-numerical cell will be left out.

Sum

The method Sum() returns the total sum of the selected range of cells.

Average

The method Avg() returns the average of the selected range of cells.

Minimum

The method Min() returns the minimum number among the selected range of cells.

Maximum

The method Max() returns the maximum number among the selected range of cells.

For more flexibility, the above functions can also be applied to single/multiple rows or columns. Learn more about selecting rows and columns.

Explore Math Functions in Excel Using C#
View on GitHub

Ready to Get Started?

Nuget Downloads 2,344,261Version:2026.10just released