- 新建一个sheet, 并用
append()
方法填充数据
from openpyxl import Workbook
book = Workbook()
sheet = book.active
sheet.title = 'student_score'
rows = [('chinese', 'sport', 'Math')
(88, 46, 57),
(89, 38, 12),
(23, 59, 78),
(56, 21, 98),
(24, 18, 43),
(34, 15, 67)
]
for row in rows:
sheet.append(row)
book.save('numbers.xlsx')
import openpyxl
import statistics as stats
book = openpyxl.load_workbook('numbers.xlsx', data_only=True)
sheet = book['student_score']
values = []
for row in sheet.iter_rows(values_only=True):
values.append(row)
values = values[1:] # skip the title