Openpyxl max_row and max_column wrongly reports a larger figure

As noted in the bug report you linked to there’s a difference between a sheet’s reported dimensions and whether these include empty rows or columns. If max_row and max_column are not reporting what you want to see then you will need to write your own code to find the first completely empty. The most efficient way, of course, would be to start from max_row and work backwards but the following is probably sufficient:

for max_row, row in enumerate(ws, 1):
    if all(c.value is None for c in row):
        break

Leave a Comment