If you've followed the link to the GitHub issue, you see that setting a note is solved in GSpread 3.7, but getting was omitted (or I'm too dense to find it). Since I needed that I wrote my own using the Google service
object. Presuming you've set up your service account credentials (same as for gspread
), create your service
:
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient import discovery
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name(filename, scope)
service = discovery.build('sheets', 'v4', credentials=creds)
With service
and the spreadsheet id
get the note(s):
fields = 'sheets/data/rowData/values/note'
ranges = ["'Sheet1'!A1")]
request = service.spreadsheets().get(spreadsheetId='1IDDMQqAV5t4Rqblahblah', ranges=ranges, fields=fields)
note_json = request.execute()
try:
note = note_json['sheets'][0]['data'][0]['rowData'][0]['values'][0]['note'] # <-- there's got to be a better way
except KeyError:
note = None
print(note)
This is independent of the gspread
model, so it's not great, but it works. I'd appreciate feedback about doing the note extraction from note_json
in a better way.