插入多个列到谷歌电子表格api PYTHON

时间:2017-06-02 11:09:41

标签: python api google-spreadsheet-api

我正在尝试使用python中的api在Google电子表格中插入多个列,现在我正在循环中这样做:

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

如果我能在一次通话中将整个列表发送到spreadSheet,或者比我的方法更好的话,我很乐意,谢谢。

1 个答案:

答案 0 :(得分:1)

根据评论中的要求,我将发布一个如何使用包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来读取/写入子范围。