如何使用Google Sheets API添加超链接? [英] How to add a hyperlink using Google Sheets API?
本文介绍了如何使用Google Sheets API添加超链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写python脚本以将超链接添加到Google表格.我正在为此使用google api.通过搜索,我收集到我需要向其余api传递"= HYPERLINK()"类型的消息.
I'm trying to write a python script to add hyperlinks to a google sheet. I'm using the google api for this. From searching, I've gathered that I need pass the rest api a "=HYPERLINK()" type of message.
{
// 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'属性.
It looks like I should be using the 'formulaValue' property.
我试图使用 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添加超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文