我正在尝试存储所有列标题及其ID的字典,以备将来使用。但是,列的迭代在第一列之后停止。 我没有进入其他专栏。
my_sheet = smartsheet_client.Sheets.get_sheet('507.......')
print(my_sheet)
col_id={}
print("\n\ncols:",type(my_sheet.columns))
def get_primary_column_id(columns):
prim_col_id=-1
for Mycolumn in columns:
print(Mycolumn.title)
col_id[Mycolumn.title]=Mycolumn.id
if (Mycolumn.primary):
prim_col_id=Mycolumn.id
print("primcol",prim_col_id)
return prim_col_id
primary_column_id = get_primary_column_id(my_sheet.columns)
print("colid",col_id)
输出:以下是my_sheet输出的一部分
At": "2019-07-11T13:46:11+00:00Z", "columns": [{"index": 0, "title": "Mid", "pri
mary": true, "width": 150, "version": 0, "validation": false, "type": "TEXT_NUMB
ER", "id": 984.....}, {"index": 1, "title": "Marketing Director", "width"
: 150, "version": 0, "validation": false, "type": "TEXT_NUMBER", "id": 100.....}, {"index": 2, "title": "Development Lead", "width": 150, "version": 0,
"validation": false, "type": "TEXT_NUMBER", "id": 548.......}, {"index": 3
, "title": "System1", "width": 150, "version": 0, "validation": false, "type": "
TEXT_NUMBER", "id": 323.....}, {"index": 4, "title": "System2", "width":
150, "version": 0, "validation": false, "type": "TEXT_NUMBER", "id": 774....}], "totalRowCount": 3, "accessLevel": "OWNER", "id": 507......, "cr
eatedAt": "2019-05-20T08:52:20+00:00Z", "resourceManagementEnabled": false}
(u'\n\ncols:', <class 'smartsheet.types.TypedList'>)
Mid
(u'primcol', 984.......)
(u'colid', {u'Mid': 984......})
答案 0 :(得分:0)
在我自己的工作表上运行相同的代码确实会打印出工作表上每列的列表及其名称和ID。您检查过表格并确认它有多列吗?
我确实在第二行注释掉了print(my_sheet)
语句,因为打印出整个工作表响应占用了我终端上的大量空间。这有助于向我展示我正在获取工作表中每列的整个列表。在此之前,我仍然获得了整个清单。删除它使其更易于阅读。