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"])

我尝试删除“A”。还是走到了最底层。我只想忽略第一列。知道怎么做吗?

4

3 回答 3

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")

弄清楚了。请享用。

于 2019-02-10T22:35:43.087 回答
0

我尝试了多行并为我工作。我有一种强烈的感觉,单行也可以正常工作。

sheet.append_rows(all_rows, table_range="A1")
于 2020-12-03T19:36:21.640 回答
-1

有点太晚了,但有同样的问题,使用 None 帮助了:

wks.append_row([None, 'B', 'C'])
于 2020-04-24T13:43:42.623 回答