【发布时间】:2016-04-01 00:59:55
【问题描述】:
我已经能够使用 Python SDK for Smartsheet 读取工作表、行、列和单元格,但我无法实际更改/写入/更新单元格值。我已经大大简化了我的代码,剩下的就是:
import smartsheet
MySS = smartsheet.Smartsheet(MyApiKey)
single_row = MySS.Sheets.get_row(SHEET_ID, ROW_ID)
destination_cell = single_row.get_column(DST_COLUMN_ID)
destination_cell.value = "new value"
single_row.set_column(destination_cell.column_id, destination_cell)
MySS.Sheets.update_rows(SHEET_ID, ROW_ID)
运行此代码时出现以下错误:
Traceback (most recent call last):
File "C:/Users/XXXXXX/Python/Smartsheet/test.py", line 24, in <module>
MySS.Sheets.update_rows(SHEET_ID, ROW_ID)
File "C:\Users\XXXXXX\Python\virtualenv PC Smartsheet\lib\site-packages\smartsheet\sheets.py", line 961, in update_rows
for item in _op['json']:
TypeError: 'long' object is not iterable
我尝试将最后一行代码中的 ROW_ID 传递为 ROW_ID 和 [ROW_ID] 和 [ROW_ID,],但仍然出现相同的错误。
我以此为参考:http://smartsheet-platform.github.io/api-docs/?python#update-row(s)
我做错了什么?
【问题讨论】:
-
您是否使用了打印语句来检查目标单元格的类型、目标单元格的值。 SHEET_ID 和 ROW_ID 不可能是它,因为它们在您阅读单元格时起作用。
-
print type(destination_cell给了我<class 'smartsheet.models.cell.Cell'>。在我尝试更改单元格之前,我得到了一个<type 'NoneType'>类型,在我更改它之后,我得到了一个类型<type 'str'> -
我不知道 smartsheets set_column 的语法,但是您是否应该只设置值?
-
我在问题中链接的 API 文档显示了这个示例:
row_a.set_column(cell_a.column_id, cell_a)。我不知道为什么;我只是在关注文档。有四个不同的 set_column 示例遵循此语法。
标签: python smartsheet-api