Excel 聚合函式
from ironxl import *

# Load existing spreadsheet
workbook = WorkBook.Load("sample.xls")
worksheet = workbook.WorkSheets[0]

# Get range from the worksheet
selected_range = worksheet["A1:A8"]

# Apply sum of all numeric cells within the range
sum_ = selected_range.Sum()

# Apply average value of all numeric cells within the range
avg = selected_range.Avg()

# Identify maximum value of all numeric cells within the range
max_ = selected_range.Max()

# Identify minimum value of all numeric cells within the range
min_ = selected_range.Min()
pip install ironxl
Excel 聚合函式

Excel 聚合函式

上面的程式代碼範例顯示如何使用 IronXL for Python 從 Excel 試算表中的一範圍儲存格中檢索聚合值。 請注意,選定範圍內的任何非數值儲存格將被排除在計算之外。

Sum

Sum() 方法返回選定範圍中的所有數值總和。

Average

Average() 方法返回選定範圍中的所有數值的算術平均值。

Minimum

Min() 方法返回選定範圍儲存格中的最小數值。

Maximum

Max() 方法返回選定範圍儲存格中的最大數值。

為了更大的靈活性,上述所有函數也可以應用於單個行或列。 學習更多關於選擇行和列。

使用Python探索Excel中的數學函數

準備好開始了嗎?

版本:2026.11剛剛發布