繁体   English   中英

gspread 从 python 填充谷歌电子表格没有属性“update_acell”

[英]gspread populate google spreadsheet from python no attribute 'update_acell'

我整个上午都在用 python 脚本填充谷歌电子表格中的一个单元格。 在运行了几个过时的教程后,我可以使用此脚本打开电子表格

import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']

credentials = ServiceAccountCredentials.from_json_keyfile_name('Apps Script Execution APIxxxxxxx.json', scope)
c = gspread.authorize(credentials)
wks = c.open_by_key ('1rwPLv6jZBhPGpf38DO6MLxx......')

wks.update_acell('A2','abc')

我已经尝试了来自不同 tuturials 的几个例子,但我找不到为什么继续给出这个错误:

AttributeError: 'Spreadsheet' 对象没有属性 'update_acell'

任何人的建议?

自己找到了答案。

您还需要定义工作表(使用 sheet1 而不是自己的给定名称)

ws = wks.get_worksheet(1)

ws.update_acell('A2','abc')

如果您选择了错误的工作表或不存在的工作表,则会出现这样的错误。 AttributeError: 'NoneType' 对象没有属性 'update_acell'

2016 年 7 月更新

如果你只有一张纸,你应该使用这个:

import json
import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://spreadsheets.google.com/feeds']

credentials = ServiceAccountCredentials.from_json_keyfile_name('YOUR_SECRET_AUTH_JSON_FILE_HERE.json', scope)

gc = gspread.authorize(credentials)


wks = gc.open("NAME OF YOUR SPREADSHEET")

ws = wks.get_worksheet(0)



ws.update_acell('A1','IT WORKS!')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM