使用Python SDK检索SmartSheet内容

时间:2016-07-28 16:31:41

标签: python sdk smartsheet-api

如此恶心尽量保持这么短。我是SmartSheet Python SDK的新手,我试图调用Smartsheet中的所有数据,并希望将其作为我自己的起点。到目前为止,我有什么

// Player triggers giveKit(), they would specify which kit they want (in a String)
// map.get(playerResponse)  <--- that would return a Kit object and then I need to instantiate that object

我在Python Shell上运行/编译,到目前为止,我正在运行它并且没有出现问题的那两行,当我尝试实现其他任何东西来提取数据时,我不断收到错误。

关于主题但是另外一件事

我也有这行代码从SmartSheet中提取特定行,

import smartsheet

smartsheet = smartsheet.Smartsheet('token1')

我的问题是,我在哪里可以找到列ID,我知道如何访问工作表ID,但我无法访问或找到智能表上的列ID,我不知道我是否忽略它。只是想朝着正确的方向下车,成为我的新手,任何帮助表示赞赏。

修改

action = smartsheet.Sheets.get_sheet(SheetID, column_ids=COL_ID, row_numbers="2,4")

编辑2

5183127460046724
Task Name

2931327646361476
Duration

7434927273731972
Start

1 个答案:

答案 0 :(得分:3)

以下示例代码从指定的Sheet中检索所有列的列表,然后遍历打印出每列的Id和Title的列。 (您显然需要将 ACCESS_TOKEN SHEET_ID 替换为您自己的值。)

# Import.
import smartsheet

# Instantiate smartsheet and specify access token value.
smartsheet = smartsheet.Smartsheet('ACCESS_TOKEN')

# Get all columns.
action = smartsheet.Sheets.get_columns(SHEET_ID, include_all=True)
columns = action.data

# For each column, print Id and Title.
for col in columns:
    print(col.id)
    print(col.title)
    print('')

更新#1

以下是一些示例代码,展示了如何在获取工作表响应中访问属性值。

# Get Sheet - but restrict results to just 2 rows (#2, #4) and a single column/cell (Id = COLUMN_ID)
action = smartsheet.Sheets.get_sheet(SHEET_ID, column_ids=COLUMN_ID, row_numbers="2,4") 

# print info from row #2 (the first row in the "Get Sheet" response) for the single specified column (cell)
print('Row #: ' + str(action.rows[0].row_number))
print('Row ID: ' + str(action.rows[0].id))
print('Column ID: ' + str(action.columns[0].id))
print('Column Title: ' + action.columns[0].title)
print('Cell (display) value: ' + action.rows[0].cells[0].display_value)
print('')

# print info from row #4 (the second row in the "Get Sheet" response) for the single specified column (cell)
print('Row #: ' + str(action.rows[1].row_number))
print('Row ID: ' + str(action.rows[1].id))
print('Column ID: ' + str(action.columns[0].id))
print('Column Title: ' + action.columns[0].title)
print('Cell (display) value: ' + action.rows[1].cells[0].display_value)
print('')