gpt4 book ai didi

Python gspread 超链接添加'

转载 作者:行者123 更新时间:2023-12-02 16:11:15 25 4
gpt4 key购买 nike

我想向单元格添加超链接。我正在使用以下代码:

cell_values = [1,'=HYPERLINK("' + some_url + '","' + some_text + '")',3]
for i, val in enumerate(cell_values):
cell_list[i].value = val
worksheet.update_cells(cell_list)

打印到单元格中的内容:

'=HYPERLINK("someLink","someText")

本应将单元格格式化为超链接,但单元格的值前面写了一个',破坏了公式的使用。

最佳答案

我认为您出现问题的原因是 value_input_option='RAW' 为默认值。看gspread的文档,好像update_cells(cell_list, value_input_option='RAW')value_input_option默认是RAW .在这种情况下,该值作为字符串放置。这样,单引号被添加到字符的顶部。

为了将 =HYPERLINK("someLink","someText") 作为公式,请使用 USER_ENTERED 的值而不是 RAW。所以当你的脚本修改时,请修改如下。

来自:

worksheet.update_cells(cell_list)

收件人:

worksheet.update_cells(cell_list, value_input_option='USER_ENTERED')

引用资料:

  • update_cells(cell_list, value_input_option='RAW')
  • ValueInputOption
    • RAW: The values the user has entered will not be parsed and will be stored as-is.
    • USER_ENTERED: The values will be parsed as if the user typed them into the UI. Numbers will stay as numbers, but strings may be converted to numbers, dates, etc. following the same rules that are applied when entering text into a cell via the Google Sheets UI.

关于Python gspread 超链接添加',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67977884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com