You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Graph API+Python请求工作表单元格值时遇OpenTypes错误求助

修复Microsoft Graph API获取Excel单元格时的OpenTypes错误

问题代码

url = 'https://graph.microsoft.com/v1.0/sites/' + siteid+ '/drive/items/' + itemid + 'workbook/worksheets/Sheet1/range/cell(row=5,column=6)'
headers = {
  'Authorization': 'Bearer ' + access_token
}

# Make a GET request to the provided url, passing the access token in a header
graph_result = requests.get(url=url, headers=headers)

# Print the results in a JSON format
print(graph_result.json())

错误信息

{'error': {'code': 'BadRequest', 'message': "Open navigation properties are not supported on OpenTypes. Property name: 'cell'.", 'innerError': {'date': '2024-07-23T19:42:36', 'request-id': 'e257e0b8-5204-4ab6-aaea-e5d72d96bb1a', 'client-request-id': 'e257e0b8-5204-4ab6-aaea-e5d72d96bb1a'}}}

解决方法

错误根源是URL路径不符合API规范:cell()方法不能嵌套在range路径下,它是工作表(worksheet)的直接可用方法,以下两种方式均可修正:

方式一:直接调用工作表的cell端点

修改URL,直接在工作表后指定单元格的行和列:

url = f'https://graph.microsoft.com/v1.0/sites/{siteid}/drive/items/{itemid}/workbook/worksheets/Sheet1/cell(row=5,column=6)'

方式二:用range指定单个单元格地址

通过address参数指定目标单元格(示例中F5对应第5行第6列):

url = f'https://graph.microsoft.com/v1.0/sites/{siteid}/drive/items/{itemid}/workbook/worksheets/Sheet1/range(address=\'F5\')'

修改后重新发送请求,即可获取包含单元格值的JSON响应。

内容的提问来源于stack exchange,提问作者Michael B redeemer216

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 16:57:09