Извлечь историю ячеек из 1000 строк одного столбца в smartsheet - PullRequest
0 голосов
/ 22 мая 2018
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= 

(leadIdentifier, rowNum, 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:
            worksheet.cell(row = (row_num + 1), column = col_num+1,value=var)
            col_num=col_num+1
            row_num=row_num+1
         col_num=1

1 Ответ

0 голосов
/ 05 июня 2018

Похоже, вы в основном на ходу.В качестве быстрого теста я создал лист, в котором для первой ячейки было задано значение «A», затем сохранено, затем значение «B», затем сохранено, и, наконец, значение «C» и сохранено.Я немного изменил ваш код (основное изменение - for cell in col: loop - 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 - довольно дорогой звонок.Я не уверен, что результаты производительности будут на большом листе.

...