YOGARAJ S
YOGARAJ S

Reputation: 1

Is it possible to get the number of rows with content present in excel sheet using openpyxl?

I tried using like this,

sheet.get_highest_row()

but the output was 104578

I have only 3 rows in my excel sheet. I need to select only the number of rows present in the Excel sheet

Upvotes: 0

Views: 2312

Answers (2)

Hildeberto Mendonca
Hildeberto Mendonca

Reputation: 133

To get the number of rows, you simply get the property max_row from the worksheet object:

rows = sheet.max_row
print(rows)

In your case, it prints 3.

Upvotes: 1

Rob
Rob

Reputation: 3513

Open the file in Excel and press Ctrl-End. This will select the last cell according to Excel. This is probably an empty cell somewhere in row 104578. If this is the case, select all empty rows in Excel, delete and save. This should update the last row.

Upvotes: 1

Related Questions