Skip to content

Instantly share code, notes, and snippets.

maksam07 /
Created June 20, 2023 12:00
pygsheets 2.0.6. Updating multiple cells with a single request. Data in dictionary format "address: value"
def update_values_batch_dict(ws, data):
keys = list(data.keys())
values = [[[val]] for val in data.values()]
return ws.update_values_batch(keys, values)
gc = pygsheets.authorize()
sh = gc.open_by_key('***')
ws = sh.worksheet_by_title('***')
maksam07 /
Last active June 20, 2023 12:04
pygsheets 2.0.6. How to find the first empty row of a google spread sheet using python GSPREAD? cols - this means what range of columns must be empty in the whole row for it to be considered writable. See
def next_available_row(sheet, cols=None):
cols = sorted([1, 2] if not isinstance(cols, list) or len(cols) != 2 else cols)
cols = sheet.get_values(
(1, cols[0]), (sheet.rows, cols[1]),
returnas='cells', include_tailing_empty_rows=True
return max([cell.address.index[0] for row in cols for cell in row if cell.value.strip()]) + 1
gc = pygsheets.authorize()