Excel

Get maximum rows containing the data in an excel sheet

def get_maximum_rows(*, sheet_object):
    rows = 0
    for max_row, row in enumerate(sheet_object, 1):
        if not all(col.value is None for col in row):
            rows += 1
    return rows

import openpyxl
workbook = openpyxl.load_workbook('result.xlsx')
# <filepath> is the  path of the excel file
sheet_object = workbook.active
max_rows = get_maximum_rows(sheet_object=sheet_object)

Last updated