-1

I find the required cell through the row number and column name (Column Search is necessary because columns can change their place in the table) and try to update its value using gspread. The code works without error, but for some reason it updates a completely different cell (A1)

import gspread

sa = gspread.service_account('path to service_account.json')
sh = sa.open('name of sheet')

wks = sh.worksheet('Sheet 1')

all = wks.get_all_records() #Get a list of dictionaries from the sheet

tab = 'Column number 3' #We will search and change the value from this column

cell_to_update = (all[0].get(tab)) #If we print() this, we get value of cell C2

wks.update(cell_to_update,'any text') 

I do not know why, but it updates cell A1, although it should update cell C2

Eugene
  • 43
  • 5

1 Answers1

0

Thanks to a tip from @BRemmelzwaal, I found the answer to my question:

all = wks.get_all_records() #Get a list of dictionaries from the sheet

tab = 'Column number 3' #We will search and change the value from this column

value_to_update = (all[0].get(tab)) #If we print() this, we get value of cell C2

cell_to_update = wks.find(str(value_to_update))

wks.update_cell(cell_to_update.row, cell_to_update.col, 'any text') 
Eugene
  • 43
  • 5