Is it possible to fetch the number of filled rows without fetching the whole spreadsheet, or find the first empty row number?
I am using the python api wrapper if it matters.
Use autofill to complete a series Highlight the cells. You'll see a small blue box in the lower right corner. Drag the blue box any number of cells down or across. If the cells form a series of dates or numbers, the series will continue across the selected cells.
Rather than retrieving all the rows into memory just to get the values in the last row, you can use the append API to append an empty table to the end of the sheet, and then parse the range that comes back in the response. You can then use the index of the last row to request just the data you want.
The main google API docs say you can do it using the WorksheetFeed. So must be possible from python.
Google Data APIs Client Library https://developers.google.com/gdata/javadoc/com/google/gdata/data/spreadsheet/WorksheetFeed (updated link 2021/10/31)
Edit: @alvaro nortes correctly pointed out the link is broken. Update the link.
Using pygsheets, this will return the number of filled rows in the spreadsheet
import pygsheets
gc = pygsheets.authorize(service_file='client_secret.json'). #authorization
worksheet = gc.open('Sign Up').sheet1. #opens the first sheet in "Sign Up"
cells = worksheet.get_all_values(include_tailing_empty_rows=False, include_tailing_empty=False, returnas='matrix')
end_row = len(cells)
print(end_row)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With