插入多列以 google 展开 sheet api PYTHON
insert multiple columns to google spread sheet api PYTHON
我正在尝试使用 python 中的 api 将多列插入到 google 电子表格中,现在我正在循环中执行此操作,就像这样:
index = 0
for a in myList:
sheet.insert_row(a, index)
index += 1
如果我可以在一次调用中将整个列表发送到电子表格,或者比我的方法更好的方法,我会很高兴。
根据评论中的要求,我将 post 一个如何使用包 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 到 read/write 的子范围。
我正在尝试使用 python 中的 api 将多列插入到 google 电子表格中,现在我正在循环中执行此操作,就像这样:
index = 0
for a in myList:
sheet.insert_row(a, index)
index += 1
如果我可以在一次调用中将整个列表发送到电子表格,或者比我的方法更好的方法,我会很高兴。
根据评论中的要求,我将 post 一个如何使用包 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 到 read/write 的子范围。