有没有一种方法可以更新我使用.find-in-gspread api for python搜索的单元格旁边的单元格

有没有一种方法可以更新我使用.find-in-gspread api for python搜索的单元格旁边的单元格,python,gspread,Python,Gspread,我正在尝试使用gspread中的.find功能定位单元格并更新其旁边的单元格 我有一些python代码,它使用了gspread api。Google表单有列名称和颜色。我可以使用.find功能搜索包含名称“Joe”的单元格,但是我需要使用另一个名为“color”的变量更新column中单元格“Joe”旁边的单元格 #Define the variables name = 'Joe' color = 'Blue' # Search the google sheet to find the loc

我正在尝试使用gspread中的.find功能定位单元格并更新其旁边的单元格

我有一些python代码,它使用了gspread api。Google表单有列名称和颜色。我可以使用.find功能搜索包含名称“Joe”的单元格,但是我需要使用另一个名为“color”的变量更新column中单元格“Joe”旁边的单元格

#Define the variables
name = 'Joe'
color = 'Blue'

# Search the google sheet to find the location of the cell named 'Joe'
sheet.find(name)
# Update the cell next to the location of the cell named 'Joe' with the color variable.
sheet.update(name, color)
我意识到sheet.update(名称、颜色)不正确,但不确定如何表达我的意图。我已经检查了gspread文档,但是我没有运气。也许还有另一种方法可以达到我不知道的效果

  • 您想在
    名称
    的下一个单元格中添加一个
    颜色
    值。
    • 关于
      名为'Joe'的单元格位置旁边的单元格
      ,当
      Joe
      为“B2”时,您希望将
      color
      的值设置为“C2”
  • 您已经能够使用gspread更新单元格
如果我的理解是正确的,这次修改怎么样?在此修改中,从
sheet.find(name)
返回的值中检索坐标。然后,使用
update\u cell()
放置
color

修改脚本: 注:
  • Joe
    为“B2”时,如果要将
    color
    的值设置为“B1”,请使用以下脚本。
    • sheet.update\u单元格(cell.row-1,cell.col,color)
  • Joe
    为“B2”时,如果要将
    color
    的值设置为“B3”,请使用以下脚本。
    • sheet.update\u单元格(cell.row+1,cell.col,color)
  • Joe
    为“B2”时,如果要将
    color
    的值设置为“A2”,请使用以下脚本。
    • sheet.update\u单元格(cell.row,cell.col-1,颜色)
参考资料:

如果我误解了你的问题,并且这不是你想要的结果,我道歉。

谢谢@Tanaike,我会在回到我的电脑并向你更新时尝试一下。非常感谢你,是的,你正确地理解了我。我只是想说谢谢你的回答,它完美地解决了我的问题。我试图将.find的结果分解为一个字符串,并将最后一个数字增加1。你的路干净多了。谢谢。@Steve谢谢你的回复。我很高兴你的问题解决了。也谢谢你。
name = 'Joe'
color = 'Blue'

cell = sheet.find(name)  # Modified
sheet.update_cell(cell.row, cell.col + 1, color)  # Modified