插入多列,以谷歌电子表格的API PYTHON

问题描述:

我试图用自己的Python API中插入多列到谷歌电子表格,现在我就是这样的一个循环中这样做:插入多列,以谷歌电子表格的API PYTHON

index = 0 
for a in myList: 
    sheet.insert_row(a, index) 
    index += 1 

我如果我可以通过一次调用将整个列表发送到spreadSheet,或者比我的方法更好,谢谢。

+0

不是你的问题的答案,但我最近尝试了'hyou'([GitHub](https://github.com/google/hyou/),[PyPi](https://pypi.python) org/pypi/hyou/1.2),[Documentation](https://hyou.readthedocs.io/en/latest/))来自Google员工,我发现它非常易于使用。 –

+0

嘿,谢谢,它是否支持在一个命令中发送所有列?如果是这样,请将我指向正确的方向,再次感谢你。 – Ayoub

+0

在调用'commit()'之前,库不会发出任何API请求。所以你可以改变行的值然后调用commit。看一个例子[这里](https://hyou.readthedocs.io/en/latest/#synopsis)。 –

正如意见中的要求我会后如何与包hyou做这样一个例子:

import hyou 


my_list = [ 
    [1, 2, 3, 4, 5], 
    [6, 7, 8, 9, 10], 
    [11, 12, 13, 14, 15], 
] 

# Login to Google Spreadsheet with credentials 
collection = hyou.login('/path/to/credentails.json') 

# Open a spreadsheet by ID 
spreadsheet = collection['1ZYeIFccacgHkL0TPfdgXiMfPCuEEWUtbhXvaB9HBDzQ'] 

# Open a worksheet in a spreadsheet by sheet name 
worksheet = spreadsheet['Sheet1'] 

# Insert values from my_list 
for row_index, row in enumerate(my_list): 
    for col_index, value in enumerate(row): 
     worksheet[row_index][col_index] = value 

# Call Worksheet.commit() to apply changes, before this no request will 
# be made to the API 
worksheet.commit() 

也看看views读/写子范围。

+0

嘿,抱歉打扰,但我怎么得到电子表格ID? – Ayoub

+0

没问题。转到浏览器中的电子表格,您可以从URL https://docs.google.com/spreadsheets/d/ /edit#gid = 0'中将其提取出来。例如。对于'docs.google.com/spreadsheets/d/1ZYeIFccacgHkL0TPfdgXiMfPCuEEWUtbhXvaB9HBDzQ/edit#gid = 0',ID是'1ZYeIFccacgHkL0TPfdgXiMfPCuEEWUtbhXvaB9HBDzQ'。 –