How to get the array of sheet ids in a folder with python

橙三吉。 提交于 2019-12-10 18:49:19

问题


When I try to get the id array from the get.folder() call (by using folder = folder.sheets.id), I get the answer: "AttributeError: 'TypedList' object has no attribute 'id'" I'm not sure what function to call in python to get the array of sheet ids in the folder.

I am trying to do this with the python smartsheet sdk, but I am not sure exactly how to format it.

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)

Also thanks for helping answer my questions, I really appreciate it.


回答1:


folder.sheets is an array. The reason you're getting an error is because there is no id attribute at the array level - you need to look at the individual elements inside the array.

Take a look at the API docs to get an example of what you'd receive.

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



回答2:


To get a list of the sheetIds for sheets in a folder, your Python would look something like this.

my_folder = ss_client.Folders.get_folder(folder_id)

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


来源:https://stackoverflow.com/questions/51658266/how-to-get-the-array-of-sheet-ids-in-a-folder-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!