I'm stuckle all morning to fill a cell in a google spreadsheet from a python script. After running through a couple of out-dated tutorials I can open the spreadsheet, using this script
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')
I've tried serveral examples from different tuturials, but I can't find why keep give this error:
AttributeError: 'Spreadsheet' object has no attribute 'update_acell'
Anyone a suggestion?
Found the answer myself.
You need to define the worksheet as well (Use sheet1 instead of the self given name)
ws = wks.get_worksheet(1)
ws.update_acell('A2','abc')
If you select the wrong sheet or sheet what don't excists, you get an error like this. AttributeError: 'NoneType' object has no attribute 'update_acell'
UPDATE JULY 2016
If you have only 1 sheet you should use this:
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!')