2

I can pull data from google spreadsheet by using

from google.colab import auth

auth.authenticate_user()
import gspread
from oauth2client.client import GoogleCredentials

gc = gspread.authorize(GoogleCredentials.get_application_default())    
worksheet = gc.open('RoutePlannerCumOptimizerInputSheet').sheet1

it does not take sheet name as parameter, my spreadsheet has three sheets, i can only access only one sheet. how to access other sheets and pull data in the same google spreadsheet. Any help is deeply appreciated.

Bob Smith
  • 36,107
  • 11
  • 98
  • 91

1 Answers1

3

Try using the get_worksheet function. Here's an example from the gspread documentation:

Select worksheet by index. Worksheet indexes start from zero:

worksheet = sh.get_worksheet(0)

Or by title:

worksheet = sh.worksheet("January")

Or the most common case: Sheet1:

worksheet = sh.sheet1

To get a list of all worksheets:

worksheet_list = sh.worksheets()
Bob Smith
  • 36,107
  • 11
  • 98
  • 91