启动程序后
results = smart.Search.search("2244113312180")
print(results)
获取数据
{"results":
[{"contextData": ["2244113312180"],
"objectId": 778251154810756,
"objectType": "row",
"parentObjectId": 3648397300262788,
"parentObjectName": "Sample Sheet",
"parentObjectType": "sheet",
"text": "2244113312180"},
{"contextData": ["2244113312180"],
"objectId": 7803446734415748,
"objectType": "row",
"parentObjectId": 3648397300262788,
"parentObjectName": "Sample Sheet",
"parentObjectType": "sheet",
"text": "2244113312180"}],
"totalCount": 2}
如何在程序中正确使用它们? 请提供一个正确的用法示例
以及如何找到在其中找到值“2244113312180”的id_列
new_row = smartsheet.models.Row()
new_row.id = results.objectId
对不起,我没有立即写下错误。我无法使用结果中的属性。字符串:
new_row.id = results.objectId
引起错误
AttributeError: 'SearchResult' object has no attribute 'objectId'
谢谢你的帮助
顺便说一下,我找到了方法
results = smart.Search.search("2244113312180")
text = str(results)
json_op = json.loads(text)
for i in json_op["results"]:
new_row = smartsheet.models.Row()
new_row.id = i["objectId"]
我不知道这是不是一个好的解决方案
根据Smartsheet API文档中的SearchResultItem Object定义,搜索结果项永远不会包含关于存在值的列的信息。正如您发布的JSON结果所示,如果在工作表的行中(即,在该行包含的任何单元格中)找到指定的值,则相应的搜索结果项将标识工作表ID(
parentObjectId
)和行ID(objectId
)然后可以使用这两个值检索行,如文档的Get Row部分所述:
然后可以遍历
row.cells
数组,检查每个单元格的value
属性,以确定它是否与之前搜索的值匹配。当您找到包含该值的cell
对象时,该cell
对象的column_id
属性将为您提供匹配值所在的列ID更新:
感谢您在原始帖子中澄清信息。我正在更新这个答案,以提供实现我前面描述的方法的完整代码示例。希望这是有帮助的
此代码示例执行以下操作:
new value
替换工作表(单元格)中出现的任何内容相关问题 更多 >
编程相关推荐