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

Smartsheet:旧工作表更新列类型为MULTI_PICKLIST失败求助

问题解决:Smartsheet MULTI_PICKLIST列更新无效及填充报错

一、列类型更新未生效的修复

你的代码存在几个关键问题导致列类型无法从TEXT_NUMBER转为MULTI_PICKLIST:

  • 拼写错误:target_sheet.get_colunm(1234567890)中的get_colunm应为get_column,这个错误会导致target_column未被正确获取,后续更新请求自然无法作用到目标列。
  • 禁用异常捕获:client.errors_as_exceptions(False)会屏蔽错误提示,即使更新请求失败也无法得知原因。建议先开启异常捕获排查问题,上线后再按需调整。
  • 参数格式问题:更新列时,options必须是字符串数组格式(如["选项A", "选项B"]),否则会导致更新失败。

修正后的列更新代码:

client = smartsheet.Smartsheet('KEY')
client.errors_as_exceptions(True)  # 开启异常捕获,方便排查问题

target_sheet = init_sheet(workspace, target_sheet_name, client)
target_column = target_sheet.get_column(1234567890)  # 修正拼写错误

update_column = smartsheet.models.Column({
    'title': 'New Column',
    'index': target_column.index,
    'level': 3,
    'type': 'MULTI_PICKLIST',
    'options': ["选项1", "选项2", "选项3"]  # 确保是正确的字符串数组
})

# 执行更新并检查结果
response = client.Sheets.update_column(target_sheet.id, target_column.id, update_column)
if response.message != 'SUCCESS':
    print(f"更新失败:{response.result}")

二、MULTI_PICKLIST单元格填充报错的解决

报错"Required object attribute(s) are missing from your request: cell.value."是因为MULTI_PICKLIST类型单元格需要明确设置cell.value字段,且值必须是对应选项的字符串数组。

正确的单元格填充示例:

# 构造要更新的单元格
cells_to_update = [
    smartsheet.models.Cell({
        'column_id': 1234567890,
        'value': ["选项1", "选项3"],  # MULTI_PICKLIST需传数组格式的选项值
        'strict': False
    })
]

# 构造行更新对象
row_update = smartsheet.models.Row({
    'id': 9876543210,  # 目标行ID
    'cells': cells_to_update
})

# 执行更新
response = client.Sheets.update_rows(target_sheet.id, [row_update])

若使用object_values,需确保cell.value与cell.object_value格式匹配,MULTI_PICKLIST的object_value是包含values数组的对象:

'object_value': {
    'values': ["选项1", "选项3"]
}

不过直接设置cell.value为数组是更简洁的实现方式。

内容的提问来源于stack exchange,提问作者Daan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 21:47:21