openpyxl-------计算数据的维度

#!/usr/bin/env python

from openpyxl import Workbook

book = Workbook()
sheet = book.active

sheet['A3'] = 39
sheet['B3'] = 19

rows = [
(88, 46),
(89, 38),
(23, 59),
(56, 21),
(24, 18),
(34, 15)
]

for row in rows:
sheet.append(row)

print(sheet.dimensions)
print("Minimum row: {0}".format(sheet.min_row))
print("Maximum row: {0}".format(sheet.max_row))
print("Minimum column: {0}".format(sheet.min_column))
print("Maximum column: {0}".format(sheet.max_column))

for c1, c2 in sheet[sheet.dimensions]:
print(c1.value, c2.value)

book.save('dimensions.xlsx')
实现效果如下:

 

 

G:\Python3.8解释器\python.exe C:/Users/Administrator/PycharmProjects/pythonProject/dimens.py
A3:B9
Minimum row: 3
Maximum row: 9
Minimum column: 1
Maximum column: 2
39 19
88 46
89 38
23 59
56 21
24 18
34 15

Process finished with exit code 0

posted @ 2023-07-25 09:33  往事已成昨天  阅读(20)  评论(0编辑  收藏  举报