Search code examples
gspread

Is it possible to get the last row filled?


In gspread, is it possible to get the last row or cell number that is filled?

The API reference page doesn't seem to help.


Solution

  • Gspread has "row_count", but I am not sure it returns all rows in a spreadsheet, or just the filled ones. If that doesn't help, there is a slightly less direct, but completely functional way to do it:

    1.) let's assume your data is in column A, and it has been filled in consecutively row by row (i.e. no skipped rows)

    2.) in another free cell in your spreadsheet--let's assume cell B1--use the native Google Sheets function COUNTA, which will count the number of values in a dataset, and specify column A as the target, i.e. "=COUNTA(A:A)"

    3.) now just request the value of cell B1 with gspread's acell, i.e. "last_row_updated = myWorksheet.acell("B1").value"