0

我目前正在尝试将 Excel 工作表导入 Smartsheet,然后获取导入工作表的行,并将它们移动到现有工作表的底部。为此,我使用 Sheets.move_row 函数。下面是该代码的片段。

response = smart.Sheets.move_rows(
result.data.id,smart.models.CopyOrMoveRowDirective({
    'row_ids': [**Help**],
    'to': smart.models.CopyOrMoveRowDestination({'sheet_id': 1174866712913796})}))

要获取有关导入工作表的信息,我使用 get_sheet 命令。我的计划是然后遍历 sheet.row 属性并找到列出“id”的位置,然后将 id 旁边的数字拉到逗号分隔的列表中。

下面是我尝试遍历行属性的片段,但我不确定如何提取行 ID,然后将它们放入逗号分隔的列表中。

 sheet_info = smart.Sheets.get_sheet(result.data.id,_dir)
print(sheet_info)

for id in sheet_info.rows:
    x = id
print (x)  #this just prints the cells category

任何帮助将不胜感激,谢谢。如需进一步说明我想要做什么,请参考我之前发布的问题。

4

1 回答 1

0

以下代码片段执行您所描述的操作。

sheetId = 3932034054809476

# get the sheet
sheet = smart.Sheets.get_sheet(sheetId) 

# iterate through the rows array and build comma-delimited list of row ids
row_ids = ''
for row in sheet.rows:
    row_ids += str(row.id) + ', '

# remove the final (excess) comma and space from the end of the row_ids string
row_ids = row_ids[:len(row_ids)-2]

print(row_ids)

更新:

正如@Isaaclele 在下面的评论中提到的那样,复制或移动行操作要求将rowIds参数指定为number[]. 上面代码片段中属性的字符串值row_ids可以转换为这种格式,如下所示:

row_ids = list(map(int, row_ids.split(',')))

另请注意(如下面的评论中所述),复制或移动行操作需要源工作表和目标工作表中的列名完全匹配。

于 2021-06-21T14:32:59.273 回答