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天試用金鑰
無需信用卡或帳戶建立