2

I just wanna read the next tab/sheet via the API in my Google Sheets Project with Python (Windows 10) Everything works for sheet1, I just want to read/edit sheet2 (and others that I will create in the project).

Tab example: https://i.sstatic.net/d4Ee9.jpg

import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_penny.json', scope)
client = gspread.authorize(creds)

penny = client.open('pennystocks').sheet1

print(penny.get_all_records())

This works: penny = client.open('pennystocks').sheet1

This doesn't: penny = client.open('pennystocks').sheet2

1 Answer 1

5
  • You want to use the sheet except for the sheet of 1st tab using gspread.
    • For example, when there are 2 sheets of "Sheet1" and "Sheet2" in a Spreadsheet, you want to use "Sheet2".

If my understanding is correct, how about this modification?

From:

penny = client.open('pennystocks').sheet1

To:

penny = client.open('pennystocks').worksheet('Sheet2')

Note:

  • client.open('pennystocks').sheet1 is open the 1st index of sheet. So for example, in your Spreadsheet, when the index of "Sheet1" is modified to "Sheet2", client.open('pennystocks').sheet1 returns "Sheet2".

Reference:

If I misunderstood your question and this was not the result you want, I apologize.

Sign up to request clarification or add additional context in comments.

2 Comments

Yea baby! That's it! Thanks! I was looking in the wrong place, I thought I could find it on the Google API code site, but it's a gspread thing. I'm new at Python - I gotta remember each "module" has it's own set of rules.
@Biks Wigglesworth Thank you for your response. I'm glad your issue was resolved. Thank you, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.