Reputation: 35
I am trying to read a sheet from Google Drive using the Google Drive/Sheets API. I was wondering how to navigate between different tabs.
(source: cachefly.net)
(Ignore the other stuff, this is a random picture demonstrating what a tab is.)
Essentially, what I want to do is be able to access the other tabs and read the text that is there as well. Each tab is in the same format. I've been able to read from the first tab and would like to do the same for the others as well.
Here is my code:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pprint
# Use credentials to interact with the Google Drive API
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'foo', scope)
client = gspread.authorize(credentials)
# Opening the first sheet
sheet = client.open("Resume Data").sheet1
# Prints the code in a nicer format
pp = pprint.PrettyPrinter()
# Extract and print all of the values
list_of_resumes = sheet.get_all_records()
# Printing
pp.pprint(list_of_resumes)
Upvotes: 0
Views: 5032
Reputation: 201388
If my understanding is correct, how about this modification?
sheet = client.open("Resume Data").sheet1
spreadsheetName = "Resume Data"
sheetName = "###" # <--- please set the sheet name here.
spreadsheet = client.open(spreadsheetName)
sheet = spreadsheet.worksheet(sheetName)
sheet = spreadsheet.get_worksheet(1)
. This means to select the sheet of 2nd index.Upvotes: 2