Python和Google Sheets可以';我不写信给B列

Python和Google Sheets可以';我不写信给B列,python,python-3.x,google-sheets,google-api,gspread,Python,Python 3.x,Google Sheets,Google Api,Gspread,我有两个列表,我试图将它们分别写入GoogleSheets文档的A列和B列,但我只能让它写入A列,只是交替成行 这是我试过写的东西!A, sheet.insert_row(fList) sheet.insert_row(gList) 下面是我尝试将其添加到COL中的内容!A-!B rows = [fList, gList] for row in rows: for column in row: sheet.insert_row(colum

我有两个列表,我试图将它们分别写入GoogleSheets文档的A列和B列,但我只能让它写入A列,只是交替成行

这是我试过写的东西!A,

sheet.insert_row(fList)
sheet.insert_row(gList)
下面是我尝试将其添加到COL中的内容!A-!B

    rows = [fList, gList]
    for row in rows:
        for column in row:
            sheet.insert_row(column)
        sheet.add_cols(1)

这导致错误,称其为无效数据类型。我如何让它完成我的要求?

我相信你的目标如下

  • fList
    gList
    是一维数组
  • 您希望将
    fList
    gList
    的值分别放在列“A”和“B”中
  • 您希望使用gspread for Python实现这一点
在您的情况下,使用“更新”方法如何?示例脚本如下所示

示例脚本: 参考:
补充: 请允许我发表以下评论:

@不幸的是,我不能理解这是两个列表,而不是很多列表。
fList
gList
的值是
fList=['781411']、['781415']、['781412']、['781416']、['701355']、['70']‌​1330'],['701346'],['‌​701352'],['782153'],‌​['701354'],['781347'‌​],[781345']
gList=[['$81.57']、['$80.91']、['$91.63']、['$91.63']、['$455.20']、['$‌​196.90'],['$282.60']‌​,['$146.10'],['$97.2‌​2'],['$166.70'],['$2‌​87.30'],['$237.50']]‌​

你说的如下

对,是的。这些就是那些清单

在这种情况下,我使用
fList=[['781411']、['781415']、['781412']、['781416']、['701355']、['70]的值又添加了一个示例脚本‌​1330'],['701346'],['‌​701352'],['782153'],‌​['701354'],['781347'‌​],[781345']
gList=[['$81.57']、['$80.91']、['$91.63']、['$91.63']、['$455.20']、['$‌​196.90'],['$282.60']‌​,['$146.10'],['$97.2‌​2'],['$166.70'],['$2‌​87.30'],['$237.50']]‌​

示例脚本:
评论不适用于长时间的讨论;此对话已结束。
fList = ['a1', 'a2', 'a3'] # Please set your actual value.
gList = ['b1', 'b2', 'b3', 'b4', 'b5'] # Please set your actual value.
spreadsheetId = "###" # Please set your Spreadsheet ID.
sheetName = "Sheet1" # Please set your sheet name.

rows = [fList, gList]
client = gspread.authorize(credentials)
spreadsheet = client.open_by_key(spreadsheetId)
sheet = spreadsheet.worksheet(sheetName)
length = max(map(len, rows)) # If the array length of "fList" and "gList" are the same, this line is not required to be used.
rows = [e + [''] * (length - len(e)) for e in rows] # If the array length of "fList" and "gList" are the same, this line is not required to be used.
sheet.update('A1', [list(e) for e in zip(*rows)])
spreadsheetId = "###" # Please set your Spreadsheet ID.
sheetName = "Sheet1" # Please set your sheet name.

# These values are from your comment.
fList = [['781411'], ['781415'], ['781412'], ['781416'], ['701355'], ['701330'], ['701346'], ['701352'], ['782153'], ['701354'], ['781347'], ['781345']]
gList = [['$81.57'], ['$80.91'], ['$91.63'], ['$91.63'], ['$455.20'], ['$196.90'], ['$282.60'], ['$146.10'], ['$97.22'], ['$166.70'], ['$287.30'], ['$237.50']]

rows = [sum(fList, []), sum(gList, [])]
client = gspread.authorize(credentials)
spreadsheet = client.open_by_key(spreadsheetId)
sheet = spreadsheet.worksheet(sheetName)
sheet.update('A1', [list(e) for e in zip(*rows)])