0

i'm wondering it that possible to create a loop through google sheets to find a value and update it?

This is my worksheet data:

enter image description here

i want to update all rows with "all" headers with other values.

I tried to solve this by this code, but it didn't gave me any response:

wks_data = eos_wks.get_values(start="",end="")

for i in wks_data:
    i=0
    if wks_data[i][3] == "All":
        eos_wks.update_values('C%d:F%d'%(i,i),['Size','0XS','00S','00M'])

        print(i)
Antonych
  • 79
  • 7
  • 1
    Yes you can do this. Download the google sheet as a CSV file and read some documentation on the csv module. Check it out here: https://docs.python.org/3/library/csv.html – MatthewSzurkowski Jun 11 '20 at 03:01
  • Thank you for reply! Does it possible to do directly in GS, without downloading CSV file? – Antonych Jun 11 '20 at 03:11
  • Most likely. Look into web scraping with Chrome driver and Selenium. Using those tools, you could just search the page for the word "All" (should probably check the length too to avoid changing values for headers with words like "Tall" for example) and change the values of the cells that way. It's tricky, but if you're insisting on not downloading the file then that's the way I would do it. Good luck and reach out anytime! – MatthewSzurkowski Jun 11 '20 at 03:21

1 Answers1

0

I solved this problem finally, this code works perfectly.

 data = np.array(eos_wks.get_all_values())
    data1 = list(map(tuple, data))
    indx = [data1.index(tupl) for tupl in data1 if tupl[2] == "All"]

    for i in indx:
        eos_wks.update_values("C{}:F{}".format(i+1,i+1),[['Size','0XS','00S','00M']])
Antonych
  • 79
  • 7
  • you can also use find. https://pygsheets.readthedocs.io/en/stable/worksheet.html#pygsheets.Worksheet.find – Nithin Jun 11 '20 at 11:52