0

I am able to pull the data using the below code in my Gsheet using the below code.

#AUTHENTICATING THE CREDENTIALS FOR CONNECTING THE SCRIPT TO GSHEET

gc = pygsheets.authorize(service_file='client_secret.json' )
# CONNECTING THE GSHEET
sh = gc.open_by_key('1Fmnp5FUmhvL-3h9yGEmx79ZMmCWaAGLN30D1yDKliC0')
# WRITING THE DATA IN GSHEET
wks = sh[3]
wks.resize(rows=row, cols=column)
wks.set_dataframe(df,(1,1))

With the above code , whenever someone moves the position of the sheet , the code writes data into the tab which is in position 3. I want to replace wks =sh[3] to a code that pulls the data to the particular name of the tab. for example to pull data in the sheet name which is datadump in the workbook.

1 Answers1

0

This happens because getting worksheet by item acess will fetch it by index. You can use worksheet_by_title instead.

sh = gc.open_by_key('1Fmnp5FUmhvL-3h9yGEmx79ZMmCWaAGLN30D1yDKliC0')
# WRITING THE DATA IN GSHEET
wks = sh.worksheet_by_title("My sheet name")

If your title is not fixed, you can access by id

sh.worksheet('id', 0)
Nithin
  • 5,470
  • 37
  • 44