每当我检索 SmartSheet 行并循环访问其中的单元格时,CHECKBOX 类型的所有单元格始终具有 displayValue 或 Null 值,无论工作表上复选框的状态如何。还有其他人经历过吗? (我正在使用他们的python sdk)
最佳答案
我相信您已经发现了 Python SDK 的一个错误。
正如我通过以下请求/响应验证的那样(使用 Postman),Kevin 的答案正确地描述了 API 本身的行为。
获取行 - 请求:
GET https://api.smartsheet.com/2.0/sheets/7359436428732292/rows/863888846677892
获取行 - 响应:
{
"id": 863888846677892,
"sheetId": 7359436428732292,
"rowNumber": 1,
"version": 88,
"expanded": true,
"accessLevel": "OWNER",
"createdAt": "2016-07-06T22:21:58Z",
"modifiedAt": "2016-07-27T01:50:46Z",
"cells": [
{
"columnId": 4509804229093252,
"value": true
},
...
]
}
在上面的示例响应中,单元格包含一个已选中的复选框 (值=true)。因此 API 本身运行正常。
但是,如果我使用 Smartsheet Python SDK要检查完全相同的单元格,value 属性被错误地设置为 null:
Python 代码:
import os
import smartsheet
os.environ['SMARTSHEET_ACCESS_TOKEN'] = 'MY_TOKEN_VALUE'
smartsheet = smartsheet.Smartsheet()
# get sheet
sheet = smartsheet.Sheets.get_sheet(7359436428732292)
print('SheetId:\n' + str(sheet.id) + '\n')
print('RowId:\n' + str(sheet.rows[0].id) + '\n')
print('ColumnId (for the checkbox column):\n' + str(sheet.columns[0].id) + '\n')
print('Column object (for the checkbox column):\n' + str(sheet.columns[0]) + '\n')
print('Cell that contains a selected Checkbox:\n' + str(sheet.rows[0].cells[0]))
此代码生成以下输出:
工作表 ID:
7359436428732292
行ID:
863888846677892
ColumnId(用于复选框列):
4509804229093252
列对象(用于复选框列):
{"index": 0, "locked": null, "systemColumnType": null, "autoNumberFormat": null, "symbol": null, "format": null, "primary": null, "options": [], "filter": null, "width": 75, "lockedForUser": null, "title": "CBcol", "hidden": null, "type": "CHECKBOX", "id": 4509804229093252, "tags": []}
包含选定复选框的单元格:
{"format": null, "displayValue": null, "linksOutToCells": null, "columnType": null, "columnId": 4509804229093252, "hyperlink": null, "value": null, "conditionalFormat": null, "strict": true, "formula": null, "linkInFromCell": null}
因此,不幸的是,Python SDK 似乎没有为复选框列(或行为类似于复选框列的“星号”等符号列)正确设置值。我建议您记录此问题 here ,以便 Smartsheet 能够识别并解决它。如果您能够在本地解决问题(即通过修改 smartsheet-python-sdk 包的本地副本),那么您还可以提交 pull request .
关于python - Smartsheet CHECKBOX 单元格始终返回为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38594429/