0
import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']

credentials = ServiceAccountCredentials.from_json_keyfile_name('TTOOL-f0b223d454c13.json', scope)

gc = gspread.authorize(credentials)

wks = gc.open("Log").sheet1

for s in gc.openall():
    print (s.title)

wks.append_row(["A", "B", "C"])

I tried removing "A". Still goes to the very bottom. I just want to ignore the first column. Any idea how to do this?

t0m3k
  • 307
  • 1
  • 14

3 Answers3

1
import gspread
from oauth2client.service_account import ServiceAccountCredentials

def next_available_row(wks):
    str_list = list(filter(None, wks.col_values(2)))  # fastest
    return str(len(str_list)+1)

scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']

credentials = ServiceAccountCredentials.from_json_keyfile_name('TOOL-fsbd3df3.json', scope)

gc = gspread.authorize(credentials)


wks = gc.open("Log").sheet1

next_row = next_available_row(wks)




wks.update_acell("B{}".format(next_row), "test")
wks.update_acell("C{}".format(next_row), "test")

figured it out. enjoy.

t0m3k
  • 307
  • 1
  • 14
0

I've tried with multiple rows and worked for me. I have a strong feeling for a single row will work fine too.

sheet.append_rows(all_rows, table_range="A1")
Mohammad Faisal
  • 1,977
  • 1
  • 18
  • 15
-1

A little too late, but had the same issue, using None helped out:

wks.append_row([None, 'B', 'C'])
thool
  • 7
  • 4