Getting the worksheet feed for a given spreadsheet


This code snippet demonstrates how to obtain a feed of worksheet entries, given an authenticated gdata.spreadsheet.service.SpreadsheetsService() client object and a worksheet key. For the sake of the example, we are going to extract the worksheets feed for the first spreadsheet in our spreadsheets feed. The example uses the interactive Python interpreter. To obtain the worksheet feed for a private spreadsheet:
>>> import gdata
>>> import gdata.docs
>>> import gdata.spreadsheet
>>> import gdata.spreadsheet.service
>>> client = gdata.spreadsheet.service.SpreadsheetsService()
>>> client.email = 'me@gmail.com'
>>> client.password = 'mypassword'
>>> client.ProgrammaticLogin()
>>> spreadsheet_feed = client.GetFeed('http://spreadsheets.google.com/feeds/spreadsheets/private/full')
>>> first_entry = spreadsheet_feed.entry[0]
>>> key = first_entry.id.text.rsplit('/')[-1]
>>> worksheets_feed = client.GetWorksheetsFeed(key)
>>> for entry in worksheets_feed.entry:
...     print entry.title.text
... 
To do the same without authentication for public spreadsheets: To obtain the worksheet feed for a private spreadsheet:
>>> import gdata.spreadsheet
>>> import gdata.spreadsheet.service
>>> client = gdata.spreadsheet.service.SpreadsheetsService()
>>> key = 'p123345abcDEF'
>>> worksheets_feed = client.GetWorksheetsFeed(key, visibility='public', projection='values')
>>> for entry in worksheets_feed.entry:
...     print entry.title.text
... 

4 comments:

vak said...

would be also interesting to see a similar thing, but for public spreadsheets

Jochen Hartmann (Google) said...

For public spreadsheets, please use the key from the URL (usually something like: http://spreadsheets.google.com/pub?key=pABCDEF123) and use the GetFeed() method with the following URI:

http://spreadsheet.google.com/feeds/worksheets/<key>/public/values

- Jochen

vak said...

Hi Jochen, wow, great it works!

(you may want to fix a typo: before "for" stand "worksheet_feed" and in "for" is "worksheets_feed")

Ajin Abraham said...

http://spreadsheet.google.com/feeds/worksheets//public/values
is not working. i had given the key of a public form and it's responding

The spreadsheet at this URL could not be found. Make sure that you have the right URL and that the owner of the spreadsheet hasn't deleted it.