有没有办法更新与我搜索的单元格相邻的单元格使用 .find in gspread api for python
Is there a way to update the cell adjacent to the cell I searched for using .find in gspread api for python
我正在尝试使用 gspread 中的 .find 功能来定位一个单元格并更新它旁边的单元格。
我有一些使用 gspread api 的 python 代码。 Google Sheet 包含名称和颜色列。我可以使用 .find 功能来搜索包含名称 "Joe" 的单元格,但是我需要使用另一个名为 [=21 的变量更新颜色列中单元格 "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(name,color) 不正确,但不确定如何表达我正在尝试做的事情。我已经检查了 gspread 文档,但是我没有运气。也许还有另一种方法可以实现我不知道的结果。
- 您想将值
color
放入 name
的下一个单元格。
- 关于
the cell next to the location of the cell named 'Joe'
,当Joe
为"B2"时,您想将color
的值置为"C2"。
- 您已经能够使用 gspread 更新单元格。
如果我的理解是正确的,这个修改怎么样?在此修改中,从 sheet.find(name)
的返回值中检索坐标。然后,使用 update_cell()
.
放置 color
修改后的脚本:
name = 'Joe'
color = 'Blue'
cell = sheet.find(name) # Modified
sheet.update_cell(cell.row, cell.col + 1, color) # Modified
注:
- 当
Joe
为"B2"时,如果要将color
的值设置为"B1",请使用以下脚本。
sheet.update_cell(cell.row - 1, cell.col, color)
- 当
Joe
为"B2"时,如果要将color
的值设置为"B3",请使用以下脚本。
sheet.update_cell(cell.row + 1, cell.col, color)
- 当
Joe
为"B2"时,如果要将color
的值设置为"A2",请使用以下脚本。
sheet.update_cell(cell.row, cell.col - 1, color)
参考文献:
如果我误解了您的问题而这不是您想要的结果,我深表歉意。
我正在尝试使用 gspread 中的 .find 功能来定位一个单元格并更新它旁边的单元格。
我有一些使用 gspread api 的 python 代码。 Google Sheet 包含名称和颜色列。我可以使用 .find 功能来搜索包含名称 "Joe" 的单元格,但是我需要使用另一个名为 [=21 的变量更新颜色列中单元格 "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(name,color) 不正确,但不确定如何表达我正在尝试做的事情。我已经检查了 gspread 文档,但是我没有运气。也许还有另一种方法可以实现我不知道的结果。
- 您想将值
color
放入name
的下一个单元格。- 关于
the cell next to the location of the cell named 'Joe'
,当Joe
为"B2"时,您想将color
的值置为"C2"。
- 关于
- 您已经能够使用 gspread 更新单元格。
如果我的理解是正确的,这个修改怎么样?在此修改中,从 sheet.find(name)
的返回值中检索坐标。然后,使用 update_cell()
.
color
修改后的脚本:
name = 'Joe'
color = 'Blue'
cell = sheet.find(name) # Modified
sheet.update_cell(cell.row, cell.col + 1, color) # Modified
注:
- 当
Joe
为"B2"时,如果要将color
的值设置为"B1",请使用以下脚本。sheet.update_cell(cell.row - 1, cell.col, color)
- 当
Joe
为"B2"时,如果要将color
的值设置为"B3",请使用以下脚本。sheet.update_cell(cell.row + 1, cell.col, color)
- 当
Joe
为"B2"时,如果要将color
的值设置为"A2",请使用以下脚本。sheet.update_cell(cell.row, cell.col - 1, color)
参考文献:
如果我误解了您的问题而这不是您想要的结果,我深表歉意。