【问题标题】:How to create a project sheet via the python SDK如何通过 python SDK 创建项目表
【发布时间】:2018-04-04 23:56:14
【问题描述】:

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

到目前为止,这是我的代码:

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: {"result": {"shouldRetry": false, “代码”:1142,“名称”:“ApiError”,“错误代码”:1142,“推荐”: "未修复问题请勿重试。", "message": "列类型 DURATION 为项目工作表保留,不能手动设置 一列。”,“refId”:“6gurrzzwhepe”,“statusCode”:400}}

有没有一种方法可以从头开始创建项目表?

我尝试将 gantt_enabled 设置为 true,但这只是触发了另一个错误,设置 'project_settings' 也是如此。

我尝试仅使用主列创建工作表,然后使用 update_sheet 设置项目设置,这告诉我:To set projectSettings, you must first enable dependencies on the sheet.

我已尝试直接在 create_sheet 和 update_sheet 中设置依赖项,但都返回:The attribute(s) sheet.dependenciesEnabled are not allowed for this operation.

我会继续尝试,但我的想法越来越少。

【问题讨论】:

    标签: python-2.7 smartsheet-api


    【解决方案1】:

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

    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_created_templates()

    【讨论】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-04
      • 2015-10-31
      • 2021-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多