Python和Google Sheets可以';我不写信给B列
我有两个列表,我试图将它们分别写入GoogleSheets文档的A列和B列,但我只能让它写入A列,只是交替成行 这是我试过写的东西!A,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
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
的值分别放在列“A”和“B”中gList
- 您希望使用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.22'],['$166.70'],['$287.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.22'],['$166.70'],['$287.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)])