[英]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.