# 跨工作表求和from openpyxl import load_workbook
path = 'D:/sample.xlsx'
wb = load_workbook(path)
data = []
for ws in wb.worksheets: # 拜訪每張工作表
data.append(ws['E5'].value) # 將E5的值加入data列表
print(sum(data)) # 印出data列表中各元素的和# 改用較淺白一點的寫法:ans = 0
for ws in wb.worksheets:
ans += ws['E5'].value
print(ans)
ans = sum([ws['E5'].value for ws in wb.worksheets])
print(ans)