我在使用 smartsheet API 和 python 将值插入“选择列表”列时遇到问题。我尝试插入的值是选项列表中的选项之一,如附图所示。我不知道如何将值插入选项列表列中的单元格,我找不到任何文档
代码:
new_row = smartsheet.models.Row()
new_row.id = row_id
new_cell = smartsheet.models.Cell() #Cell configuration
new_cell.column_id = 5727843499960196
new_cell.value = "Jysk Bumpers"
new_cell.strict = False
new_row.cells.append(new_cell)
updated_row = smartsheet_client.Sheets.update_rows(1398305516218244, # sheet_id
[new_row])
print("Complete")
输出:
{"response": {"statusCode": 400, "reason": "Bad Request", "content": {"detail": {"index": 0, "rowId": 8212749243377540}, "errorCode": 1235, "message": "Value is not supported for this column type. Use objectValue instead.", "refId": "wv6as6"}}}
Complete
我尝试使用 objectValue 但仍然无法成功。
以下代码示例更新现有行中的 3 个单元格:
- 第一个单元格是
Text/Number
列类型 - 第二个单元格是
Dropdown list
允许每个单元格有多个值的列类型 - 第三个单元格是一个
Dropdown list
列类型,每个单元格只允许一个值
# Define cell object (for the value in the first (primary) column - a text column)
cell1 = smartsheet_client.models.Cell({
'column_id': 3838793372985220,
'object_value': 'new item'
})
# Define cell object (for the value in the second column - a multi-select dropdown)
cell2 = smartsheet_client.models.Cell({
'column_id': 3749273671624580,
'object_value': smartsheet_client.models.MultiPicklistObjectValue({'values': ['blue', 'green', 'yellow']})
})
# Define cell object (for the value in the third column - a single-select dropdown)
cell3 = smartsheet_client.models.Cell({
'column_id': 8295973295810436,
'object_value': 'cat 2'
})
# Create row that contains the 3 cells defined previously
row = smartsheet_client.models.Row({
'id': 1724835021973380,
'cells': [cell1, cell2, cell3]
})
# Update row
sheetId = 1303196942526340
result = smartsheet_client.Sheets.update_rows(sheetId, [row])
根据您包含的屏幕截图,看起来您要填充的单元格位于Dropdown list
允许每个单元格有多个值的列中 - 因此您将使用上面显示的方法来cell2
设置该单元格的值床单。请注意,在上面的代码示例中,我为 中的多选下拉列表指定了 3 个值cell2
:
smartsheet_client.models.MultiPicklistObjectValue({'values': ['blue', 'green', 'yellow']})
Jysk Bumpers
...但是如果这是您希望为该单元格选择的唯一项目,您可以只指定一个值 ( )。
smartsheet_client.models.MultiPicklistObjectValue({'values': ['Jysk Bumpers']})