I am writing a python(ver 3) script to access google doc using gspread.
1) import gspread
2) from oauth2client.service_account import ServiceAccountCredentials
3) scope = ['https://spreadsheets.google.com/feeds']
4) credentials = ServiceAccountCredentials.from_json_keyfile_name(r'/path/to/jason/file/xxxxxx.json',scope)
5) gc = gspread.authorize(credentials)
6) wks = gc.open("test").sheet1
test is a google sheet which seems to be opened and read fine but if I try to read from a Office excel file it gives me error.here is what they look:
The folder which test and mtg are under is shared with the email I got in json file.Also both files were shared with that email.
Tried:
wks = gc.open("mtg.xls").sheet1
and
wks = gc.open("mtg.xls").<NameOfFirstSheet>
and
wks = gc.open("mtg").<NameOfFirstSheet>
error:
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/gspread/client.py", line 152, in open raise SpreadsheetNotFound gspread.exceptions.SpreadsheetNotFound
There is no .xls
to be added at the end of the file name, the data is saved in a different format (and can later be exported as .xls
).
Try to break your code into:
ss = open("MTG_Collection_5_14_16")
ws = ss.worksheet("<NameOfFirstSheet>")
and post the error message if any.
Spreadsheet
instances have an attribute sheet1
because it is the default name for the first worksheet. ss.sheet1
actually returns the worksheet with index 0, no matter what its name is.
If you want to access another worksheet, you need to use one of ss.worsheet("<title>")
or ss.get_worksheet(<index>)
. ss.<NameOfFirstSheet>
will not work.