【发布时间】:2020-09-07 10:06:47
【问题描述】:
我正在使用 Python 中的 gspread 模块创建一个应用程序,该应用程序涉及电子表格中的动态行数。
每当用户添加新的 Pinterest Pin 时,程序都应该在底部再追加一行。我可以用以下代码模拟这一行:
client = gspread.authorize(SAC.from_json_keyfile_name("WROS-Editor.json", ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']))
spreadsheet = client.open("WROS")
pinterest_sheet = spreadsheet.worksheet("Pinterest Pins")
pinterest_sheet.append_row([""]) # Simulating when the user creates a new pin
这可以按预期在底部添加 1 行:
但是,当我调用该函数两次时,没有附加新行。以下代码的输出与上一个屏幕截图相同。
pinterest_sheet.append_row([""]) # Just adds 1 new row, should add 2 new rows.
pinterest_sheet.append_row([""])
当我使用add_rows() 函数时,也会出现同样的问题。当我调用该函数两次(每次添加 1 行,即pinterest_sheet.add_rows(1))时,它只添加了 1 行。如果我将添加行的第二个数字更改为 2,它总共添加 2 行(应该添加 3)。
pinterest_sheet.add_rows(1) # Only adds 2 rows in total, should add 3 rows.
pinterest_sheet.add_rows(2)
为什么会出现这个问题,我该如何解决?
【问题讨论】:
标签: python google-sheets-api gspread