Skip to content

Instantly share code, notes, and snippets.

@egor83
Last active September 14, 2016 21:01
Show Gist options
  • Save egor83/4634422 to your computer and use it in GitHub Desktop.
Save egor83/4634422 to your computer and use it in GitHub Desktop.
Working with Google spreadsheets with Python GData API
client = gdata.spreadsheets.client.SpreadsheetsClient()
token.authorize(client)
sps = client.GetSpreadsheets()
print len(sps.entry) # shows how many spreadsheets you have
sprd_key = 'put an appropriate spreadsheet key here'
wss = client.GetWorksheets(sprd_key) # get a list of all worksheets in this spreadsheet, to look around for info in a debugger
ws = client.GetWorksheet(sprd_key, 'od6') # get the first worksheet in a spreadsheet; seems 'od6' is always used as a WS ID of the first worksheet
cq = gdata.spreadsheets.client.CellQuery(3,3,1,1) # form a query to get a cell in R3C1
cs = client.GetCells(sprd_key, 'od6', q=cq)
cell_ent = cs.entry[0]
print cell_ent.cell.input_value # get a current cell value
cell_ent.cell.input_value = '112'
client.Update(cell_ent) # update a cell entity, sending info back to Google
@rhaleblian
Copy link

1 also works as an id for the first worksheet.

@scardine
Copy link

Thanks for the example, could not find anything at https://developers.google.com/.

Sorry if it is a dumb question, but how am I supposed to get the spreadsheet key? I've inspected the elements returned by client.GetSpreadsheets() but could not find any value that works as the spreadsheet key.

[update]

Silly me, its there is a get_spreadsheet_key() method. How could I miss it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment