从Python附加Google表格中的列表 [英] Append a list in Google Sheet from Python

查看:50
本文介绍了从Python附加Google表格中的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python列表,我只想在Google表格的第一行中逐行编写(附加).我已经完成了所有初始身份验证部分,这是代码:

I have a list in Python which I simply want to write (append) in the first column row-by-row in a Google Sheet. I'm done with all the initial authentication part, and here's the code:

credentials = GoogleCredentials.get_application_default()
service = build('sheets', 'v4', credentials=credentials)

对于如何轻松实现此目的,我一无所知.

I do not have any clue as to how I could possibly do this in an easy way.

推荐答案

该示例脚本如何?此示例将 list 附加到列A.作为数据的列表是二维数组.请注意这一点.为了使用此脚本,请在API控制台上启用Sheet API v4.

How about this sample script? This sample appends list to column A. The list as data is 2 dimensional array. Please be careful for this. In order to use this script, please enable Sheet API v4 at API console.

credentials = GoogleCredentials.get_application_default()
service = build('sheets', 'v4', credentials=credentials)

list = [["valuea1"], ["valuea2"], ["valuea3"]]
resource = {
  "majorDimension": "ROWS",
  "values": list
}
spreadsheetId = "### spreadsheet ID"
range = "Sheet1!A:A";
service.spreadsheets().values().append(
  spreadsheetId=spreadsheetId,
  range=range,
  body=resource,
  valueInputOption="USER_ENTERED"
).execute()

您可以在此处.

如果这个样本对您没有用,很抱歉.

If this sample was not useful for you, I'm sorry.

这篇关于从Python附加Google表格中的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆