import openpyxl
def last_active_row():
workbook = openpyxl.load_workbook(input_file)
wp = workbook[sheet_name]
last_row = wp.max_row
last_col = wp.max_column
for i in range(last_row):
for j in range(last_col):
if wp.cell(last_row, last_col).value is None:
last_row -= 1
last_col -= 1
else:
print(wp.cell(last_row,last_col).value)
print("The Last active row is: ", (last_row+1)) # +1 for index 0
if __name__ = '___main__':
last_active_row()
3条答案
按热度按时间zu0ti5jz1#
s.rows
是一个生成器,其列表包含每行单元格的数组。6psbrbz92#
如果你正在使用python和openpyxl查找整个xlsx表的最后一个非空行。
这应该有帮助。
eqqqjvef3#
openpyxl
的类Worksheet
具有属性max_rows