Python调用Smartsheet API向行添加单元格时缺失cell.columnId报错
问题原因
你遇到的报错是属性名大小写拼写错误以及赋值属性使用错误导致的:
- Smartsheet Python SDK 中 Cell 模型的列ID属性是
columnId(末尾d为小写),你代码中写的columnID(末尾D为大写)是完全独立的另一个自定义属性,不会被SDK识别写入请求体,所以接口判定你缺失了必填的cell.columnId参数。 displayValue是接口返回数据时的只读属性,手动给单元格赋值需要使用value属性。
修正后的代码
import smartsheet smartsheet_client = smartsheet.Smartsheet(access_token) sheet = smartsheet_client.Sheets.get_sheet(sheetID) for column in sheet.columns: if column.title == "Document Type": thisColumn = column.id newRow = smartsheet_client.models.Row() newCell = smartsheet_client.models.Cell() # 修改为正确的属性名 columnId,不要写columnID newCell.columnId = thisColumn # 赋值使用value属性,不要用displayValue newCell.value = 'Test' print("newCell.columnId ==", newCell.columnId) print("type(newCell.columnId) ==", type(newCell.columnId)) print() newRow.cells.append(newCell) smartsheet_client.Sheets.add_rows(sheetID, newRow)
内容的提问来源于stack exchange,提问作者imjellybaby
相关产品推荐
相关产品推荐

