获取智能表中单列1000行的单元格历史记录

时间:2018-05-22 04:28:42

标签: smartsheet-api

'$2,000.00'

(leadIdentifier,的rowNum,rev.modified_by.name,rev.modified_by.email,STR(rev.modified_at),rev.value)            excelrows.append(excelrow)

for i in range(sheet.total_row_count):
    row_id = sheet.rows[i].id
    rows = smartsheet.Sheets.get_row(SHEET_ID,row_id)
    col=rows.cells
    rowNum=rows.row_number
    for cell in col._TypedList__store:
        if cell.column_id == leadidentcol:
            leadIdentifier=cell.display_value
            print(leadIdentifier)      
    cell_history = 
    smartsheet.Cells.get_cell_history(SHEET_ID,row_id,colid,include_all= True)
    revisions=cell_history.data
    excelrows=[]
    for rev in revisions:
        excelrow= 

1 个答案:

答案 0 :(得分:0)

看起来你大部分时间都在轨道上。作为一个快速测试,我创建了一个工作表,其中第一个单元格被设置为值' A'然后保存,然后值' B'然后保存,最后值' C& #39;并保存。我稍微修改了你的代码(主要的变化是for cell in col:循环 - TypedList是一个迭代器)到:

def cell_history(sheet):

    for i in range(sheet.total_row_count):
        row_id = sheet.rows[i].id
        rows = ss.Sheets.get_row(sheet.id, row_id)
        col = rows.cells
        leadidentcol = sheet.columns[0].id
        row_num = rows.row_number
        for cell in col:
            if cell.column_id == leadidentcol:
                lead_identifier = cell.display_value
                print(lead_identifier)

        cell_history = ss.Cells.get_cell_history(sheet.id,row_id, sheet.columns[0].id, include_all= True)
        revisions = cell_history.data
        excelrows = []
        for rev in revisions:
            excelrow = (lead_identifier, row_num, rev.modified_by.name, rev.modified_by.email, str(rev.modified_at),
                        rev.value)
            excelrows.append(excelrow)
        for exlrows in excelrows:
            for var in exlrows:
                print(var)

对我的样本表运行此结果导致此输出:

C
1
Tim Wells
timwells@example.com
2018-06-04 21:26:38+00:00
C
C
1
Tim Wells
timwells@example.com
2018-06-04 21:26:30+00:00
B
C
1
Tim Wells
timwells@example.com
2018-06-04 21:26:23+00:00
A

请注意,get_cell_history是一项相当昂贵的电话。我不确定在大张纸上会有什么效果。