python - SmartSheet API python 扩展对象
问题描述
SmartSheet SDK API 中有几个对象是对象的扩展。例如,CellLink 和 ObjectValue 是 Cell 对象的扩展。我已经阅读并了解这些是父/子类并且涉及继承。但是,我仍然无法理解这个概念,我无法弄清楚创建 CellLink 对象的语法。
new_cell = ss.models.Cell()
linked_cell = ss.models.Cell()
linked_cell.column_id = int(columnid)
linked_cell.sheet_id = int(sheetid)
linked_cell.row_id = int(rowid)
new_cell.link_in_from_cell = linked_cell
上面的示例为我提供了最丰富的错误消息,因此,我认为它最接近我尝试过的所有变体的正确语法。对此示例以及可能的基本概念的任何帮助将不胜感激。
raise ValueError("`{0}` invalid type for {1} value".format(value,
self.object_type))
ValueError: `{"columnId": 2068210422966148}` invalid type for <class
'smartsheet.models.cell_link.CellLink'> value
我相信我已经找到了这个问题的答案。似乎您只需要创建一个属性字典,例如:
ex_dict = {sheet_id: 0974792938, column_id: 07263839242, row_id:
2632938474839}
new_cell.link_in_from_cell = ex_dict
诀窍在代码的后面。而不是创建一个新行,如:
row = ss.models.Row()
您需要更新现有行,例如:
row = ss.Sheets.get_row(sheet_id, row_id)
但是,我仍然有一个奇怪的错误:字段“createdAt”是意外类型。
解决方案
您应该发送仅包含您希望更改的属性的 Row 和 Cell 对象。您不想尝试修改现有的 Row 对象(例如使用createdAt
属性,而是分配一个具有适当行 ID 和单元格的新对象以进行更新。
有关创建单元格链接的完整示例,请参阅https://github.com/smartsheet-samples/python-snippets/blob/04951c2ca8ae1a97386bdd3fa6e010f2845e1421/samples.py#L45 。
推荐阅读
- mysql - 如何在 Mysql 中使用准备语句来使用数据库
- reactjs - Webpack 5 - 导入 axios 后出现“意外令牌:punc (.)”
- azure - 在 Azure AD 中自动化身份提供者 (IdP) 发起的 SSO 的最佳方法
- php - 如何使用 PHP 和 MySql 对饼图进行分类
- node.js - 币安测试网部署错误:无法从您的助记词或私钥创建地址
- javascript - 从 Django 服务器触发 javascript 函数
- php - Apache/php 不会运行 shell 脚本
- javascript - JavaScript eventListener 不是函数错误
- python - 将数据附加到多维 numpy 数组
- react-select - 你如何告诉一个反应选择