作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想向单元格添加超链接。我正在使用以下代码:
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')
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/
我是一名优秀的程序员,十分优秀!