Python/gspread - how can I update multiple cells with DIFFERENT VALUES at once?

0 views
Skip to first unread message

ivan98 via StackOverflow

unread,
Oct 12, 2016, 5:40:06 AM10/12/16
to google-appengin...@googlegroups.com

Assuming a table with a header row, as follows:

Name  | Weight
------+-------
Apple | 56
Pear  | 23
Leaf  | 88

Then, the following should be self explanatory

cell_list = []

# get the headers from row #1
headers = worksheet.row_values(1)
# find the column "Weight", we will remember this column #
colToUpdate = headers.index('Weight')

# task 1 of 2
cellLookup = worksheet.find('Leaf')
# get the cell to be updated
cellToUpdate = worksheet.cell(cellLookup.row, colToUpdate)
# update the cell's value
cellToUpdate.value = 77
# put it in the queue
cell_list.append(cellToUpdate)

# task 2 of 2
cellLookup = worksheet.find('Pear')
# get the cell to be updated
cellToUpdate = worksheet.cell(cellLookup.row, colToUpdate)
# update the cell's value
cellToUpdate.value = 28
# put it in the queue
cell_list.append(cellToUpdate)

# now, do it
worksheet.update_cells(cell_list)


Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/16675258/python-gspread-how-can-i-update-multiple-cells-with-different-values-at-once/39995164#39995164
Reply all
Reply to author
Forward
0 new messages