Gsheet Python.Добавить строку и игнорировать первый столбец.Как? - PullRequest
0 голосов
/ 10 февраля 2019
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"])

Я попытался удалить "A".Все еще идет к самому низу.Я просто хочу игнорировать первый столбец.есть идеи как это сделать?

1 Ответ

0 голосов
/ 11 февраля 2019
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")

разобрался.наслаждаться.

...