1

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 :

enter image description here

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!

Maxime Campeau
  • 109
  • 1
  • 8
  • 1
    Possible duplicate of [How to find the last row in a column using openpyxl normal workbook?](https://stackoverflow.com/questions/33541692/how-to-find-the-last-row-in-a-column-using-openpyxl-normal-workbook) – Chris Mar 11 '19 at 16:08

2 Answers2

1

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)
Maxime Campeau
  • 109
  • 1
  • 8
  • This is correct, but does NOT give the last nonblank row . If a row was previously edited in the Excel, max_row will include that , even if it is blank. – Joshua Fox Mar 11 '19 at 16:05
1

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.

Joshua Fox
  • 18,704
  • 23
  • 87
  • 147