Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 如何通过python SDK创建项目工作表_Python 2.7_Smartsheet Api - Fatal编程技术网

Python 2.7 如何通过python SDK创建项目工作表

Python 2.7 如何通过python SDK创建项目工作表,python-2.7,smartsheet-api,Python 2.7,Smartsheet Api,我正在尝试在文件夹中创建新的项目工作表,但是我找不到确保该工作表是项目工作表的方法 以下是我目前的代码: def create_resource_sheet(name): """ Create a new resource sheet. :param name: :return: """ folder_id = get_resource_folder_id() # TODO: Find and delete existing sheet wit

我正在尝试在文件夹中创建新的项目工作表,但是我找不到确保该工作表是项目工作表的方法

以下是我目前的代码:

def create_resource_sheet(name):
    """ Create a new resource sheet.

    :param name:
    :return:
    """
    folder_id = get_resource_folder_id()

    # TODO: Find and delete existing sheet with this name

    resource_sheet = SS.models.Sheet({
        'name': name,
        # 'gantt_enabled': True,  # This was added as an attempt to force it to a project sheet, but error 1032
        'columns': [{
            'title': 'Task',
            'type': 'TEXT_NUMBER',
            'primary': True,
            'width': 200
        }, {
            'title': 'Status',
            'type': 'PICKLIST',
            'options': ['wtg', 'hld', 'ip', 'rdy', 'rev', 'fin', 'omt'],  # TODO: Update this list
            'width': 180
        }, {
            'title': '% Complete',
            'type': 'TEXT_NUMBER',
            'tag': ['GANTT_PERCENT_COMPLETE'],
            'width': 85
        }, {
            'title': 'Assigned To',
            'type': 'CONTACT_LIST',
            'tag': ['GANTT_ASSIGNED_RESOURCE', 'GANTT_DISPLAY_LABEL'],
            'width': 150
        }, {
            'title': '% Use',
            'type': 'TEXT_NUMBER',
            'tag': ['GANTT_ALLOCATION'],
            'width': 60
        }, {
            'title': 'Days',
            'type': 'DURATION',
            'tag': ['GANTT_DURATION'],
            'width': 70
        }, {
            'title': 'Start',
            'type': 'ABSTRACT_DATETIME',
            'tag': ['CALENDAR_START_DATE', 'GANTT_START_DATE'],
            'width': 80
        }, {
            'title': 'Start',
            'type': 'ABSTRACT_DATETIME',
            'tag': ['CALENDAR_START_DATE', 'GANTT_START_DATE'],
            'width': 80
        }, {
            'title': 'Finish',
            'type': 'ABSTRACT_DATETIME',
            'tag': ['CALENDAR_END_DATE', 'GANTT_END_DATE'],
            'width': 80
        }, {
            'title': 'Type',
            'type': 'TEXT_NUMBER',
            'width': 150
        }, {
            'title': 'Comments',
            'type': 'TEXT_NUMBER',
            'width': 700
        }
        ]
    })

    response = SS.Folders.create_sheet_in_folder(folder_id, resource_sheet)
    new_sheet = response.result
    return new_sheet
我收到以下错误代码:

smartsheet.exceptions.ApiError:{“结果”:{“shouldRetry”:false, “代码”:1142,“名称”:“APIRERROR”,“错误代码”:1142,“建议”: “未解决问题,请勿重试。”,“消息”:“列类型” 工期为项目图纸保留,不能手动设置 列“,”refId:“6gurrzzwheep”,“statusCode”:400}

有没有办法从头开始创建项目图纸

我曾尝试将gantt_enabled设置为true,但这只是触发了一个不同的错误,设置“项目_设置”也是如此

我已尝试仅使用主列创建工作表,然后更新工作表以设置项目设置,这告诉我:
要设置项目设置,必须首先启用工作表上的依赖项。

我已尝试直接在“创建”工作表和“更新”工作表中启用依赖项,但两者都返回:
属性工作表。此操作不允许启用依赖项。


我将继续尝试,但我已经失去了想法。

使用模板创建工作表,如果您想自定义,可以使用全局项目模板或用户定义的模板

templates = SS.Templates.list_public_templates()
for template in templates.data:
    if template.global_template == 
smartsheet.models.enums.GlobalTemplate.PROJECT_SHEET:
    break
sheet = smartsheet.models.Sheet({
    'name': name,
    'from_id': template.id
})
resource_sheet = SS.Folders.create_sheet_in_folder(folder_id, sheet)

如果要使用Smartsheet web UI自定义创建项目工作表,请进行更改,然后另存为模板。拥有模板后,如果不想搜索,请从属性中获取ID,或者
SS.Templates.list_user\u created_Templates()

使用全局项目模板或用户定义的模板(如果要自定义)从模板创建图纸

templates = SS.Templates.list_public_templates()
for template in templates.data:
    if template.global_template == 
smartsheet.models.enums.GlobalTemplate.PROJECT_SHEET:
    break
sheet = smartsheet.models.Sheet({
    'name': name,
    'from_id': template.id
})
resource_sheet = SS.Folders.create_sheet_in_folder(folder_id, sheet)

如果要使用Smartsheet web UI自定义创建项目工作表,请进行更改,然后另存为模板。拥有模板后,如果不想搜索,请从属性中获取ID,或者
SS.Templates.list\u user\u created\u Templates()

无法通过API创建新的启用依赖关系的工作表。您需要手动创建模板,然后使用API进行复制。

您无法通过API创建新的启用依赖项的工作表。您需要手动创建模板,然后使用API进行复制。

谢谢@timwells。我最终使用了类似的技术。我做了一个模板表,其中包含我需要的最小列。由于与其他工作表相比,某些工作表可能需要额外的列,因此我最终基于模板创建了工作表,然后以编程方式修改这些列(主要是添加新列)。谢谢@timwells。我最终使用了类似的技术。我做了一个模板表,其中包含我需要的最小列。由于与其他工作表相比,某些工作表可能需要额外的列,因此我最终基于模板创建了工作表,然后以编程方式修改这些列(主要是添加新列)。