gpt4 book ai didi

google-sheets-api - 如何使用 Google Sheets API 添加超链接?

转载 作者:行者123 更新时间:2023-12-04 16:29:32 24 4
gpt4 key购买 nike

我正在尝试编写一个 python 脚本来将超链接添加到 google 表格。我正在为此使用 google api。通过搜索,我了解到我需要向其余 api 传递“=HYPERLINK()”类型的消息。

来自文档:https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#ExtendedValue.FIELDS.formula_value

{
// Union field value can be only one of the following:
"numberValue": number,
"stringValue": string,
"boolValue": boolean,
"formulaValue": string,
"errorValue": {
object(ErrorValue)
}
// End of list of possible types for union field value.
}

看起来我应该使用“formulaValue”属性。

编辑:我尝试使用 UpdateCells要求

编辑:下面的解决方案。

最佳答案

我想通了:

def addHyperlink(self, hyperlink, text, sheetId, rowIndex, colIndex):
requests = []
requests.append({
"updateCells": {
"rows": [
{
"values": [{
"userEnteredValue": {
"formulaValue":"=HYPERLINK({},{})".format(hyperlink, text)
}
}]
}
],
"fields": "userEnteredValue",
"start": {
"sheetId": sheetId,
"rowIndex": rowIndex,
"columnIndex": colIndex
}
}})
body = {
"requests": requests
}
request = self.service.spreadsheets().batchUpdate(spreadsheetId=self.spreadsheetId, body=body)
return request.execute()

关于google-sheets-api - 如何使用 Google Sheets API 添加超链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53632838/

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