我无法重现您描述的问题。
我正在测试的报告包含以下数据。第一行中的 Google 链接是指向 https://www.google.com 的普通 URL,第二行中的 Contacts List 链接是指向 Smartsheet 中另一个工作表的工作表超链接。
首先,我使用 Python SDK 获取报告,然后打印出第一行第二个单元格的内容(即包含Google 超链接的单元格):
reportID = 6667768033503108
report = smartsheet_client.Reports.get_report(reportID)
print(report.rows[0].cells[1])
此代码的结果显示以下输出(此处为 JSON 格式以便于阅读):
{
"columnId": 5228827298293636,
"displayValue": "Google",
"hyperlink": {
"url": "https://www.google.com"
},
"value": "Google",
"virtualColumnId": 2581703205119876
}
所以,访问超链接的URL可以通过以下代码完成:
url = report.rows[0].cells[1].hyperlink.url
print(url) #shows output: https://www.google.com
同样的方法适用于获取第二行中工作表超链接的 URL。即,运行以下代码:
reportID = 6667768033503108
report = smartsheet_client.Reports.get_report(reportID)
url = report.rows[1].cells[1].hyperlink.url
print(url) #shows output: https://app.smartsheet.com/sheets/[ID]
这种方法应该适合您,但如果由于某种原因您看到包含链接的单元格的 JSON 响应中的单元格对象(使用 Python SDK 时)实际上并不包含 hyperlink具有url 属性的对象——这可能表明 Python SDK 或底层 API 存在错误。在这种情况下,您可以尝试使用字典获取 URL 字符串,如以下代码所示。 (注意:您需要import json 才能使用此代码)。
reportID = 6667768033503108
# get the report
report = smartsheet_client.Reports.get_report(reportID)
# load the contents of the second cell in the first row
resp_dict = json.loads(str(report.rows[0].cells[1]))
# read the url property from the dictionary
url = resp_dict['hyperlink']['url']
print(url) #shows output: https://www.google.com