Reputation: 109
for a script I created I would need to find a way to get the count of rows with values in an xlsx file. For instance :
The function would need to return, for example, x=9.
I've tried a few things but nothing does it. Any openpxyl master that could shed some light over this?
Thanks, once again!
Upvotes: 1
Views: 2506
Reputation: 19675
As @Maxime Campeau said, there is an API for that in Openpyxl. But this is not the last non-blank row. This is the last row that was "never touched." For example, if someone edited, then deleted, row 1000, then max_row
will be 1000 even if rows 100 and above are blank.
No library or API is available for this: If you want an accurate answer, take max_row
and max_column
and scan backwards until you hit a non-blank cell.
Upvotes: 1
Reputation: 109
As I ask my question, I come across the answer. For those interested :
wb = openpyxl.load_workbook('PATH')
sheet = wb['SHEET NAME']
nb_row = sheet.max_row
print(nb_row)
Upvotes: 1