Reputation: 33
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
Upvotes: 2
Views: 3114
Reputation: 201378
If my understanding is correct, how about this modification?
penny = client.open('pennystocks').sheet1
penny = client.open('pennystocks').worksheet('Sheet2')
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".If I misunderstood your question and this was not the result you want, I apologize.
Upvotes: 5