【问题标题】:How to get the array of sheet ids in a folder with python如何使用python获取文件夹中的工作表ID数组
【发布时间】:2019-01-10 11:59:24
【问题描述】:

当我尝试从 get.folder() 调用中获取 id 数组时(通过使用 folder = folder.sheets.id),我得到了答案:“AttributeError: 'TypedList' object has no attribute 'id'”我不确定在 python 中调用什么函数来获取文件夹中的工作表 ID 数组。

我正在尝试使用 python smartsheet sdk 执行此操作,但我不确定如何格式化它。

inc_list = ['all'] # you can add other parameters here, separated by a comma
 response = ss_client.Folders.copy_folder(
  folderID,                           # folder_id
  ss_client.models.ContainerDestination({
    'destination_id': destinationID,
    'destination_type': 'folder',
    'new_name': cellValue
  }),
include=inc_list
)

copiedFolderID = response.result.id

folder = ss_client.Folders.get_folder(
  copiedFolderID)       # folder_id 

newFolder = folder.sheets.id

print (newFolder)

也感谢您帮助回答我的问题,非常感谢。

【问题讨论】:

标签: python api smartsheet-api smartsheet-api-2.0


【解决方案1】:

folder.sheets 是一个数组。您收到错误的原因是数组级别没有 id 属性 - 您需要查看数组中的各个元素。

查看API docs 以获取您将收到的示例。

sheet_ids = []
for sheet in folder.sheets
    sheet_ids.append(sheet.id)
print(sheet_ids)

【讨论】:

  • 成功了!非常感谢,现在我可以开始创建用于编辑所有文档名称的循环了。
【解决方案2】:

要获取文件夹中工作表的 sheetId 列表,您的 Python 应如下所示。

my_folder = ss_client.Folders.get_folder(folder_id)

for sheet in my_folder.sheets:
    print(sheet.id)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-06
    • 1970-01-01
    • 2013-12-14
    相关资源
    最近更新 更多