#the code
def write_to_dangersheet(flow):
credentials_file = "file.json"
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name(credentials_file, scope)
gc=gspread.authorize(credentials)
test_wb=gc.open_by_key('yyyyyyyyyyyyyy').worksheet('betaflow')
f=[phonenumber,date," ",flow,]
if flow=='webhook-test':
test_wb.append_row(f)
write_to_dangersheet(flow)
Use table_range
parameter of append_row()
to explicitly specify the table range:
worksheet.append_row(['Test1', '', 'Test2'], table_range='A1')
Background:
Worksheet.append_row()
method corresponds to Sheets API spreadsheets.values.append
.
When spreadsheets.values.append
is called, it searches for logical "table" to append a row of values. Values will be appended to the next row of the table, starting with the first column of the table.
Depending on the data in your spreadsheet there could be several potential "tables" (usually separated by empty columns or rows). By default append_row()
does not specify which "table" to use and lets Sheets API detect the table implicitly. In cases where there are multiple tables, Sheets API could select the "table" you didn't intend to append to. In such cases, you need to explicitly tell the API which logical "table" you would like to use.
Appending values section of Google Sheets API v4 docs has a good example of multiple tables in a sheet.
© 2022 - 2025 — McMap. All rights reserved.