Store results of Excel calculation

Is it possible to store and/or memoize the results of an Excel calculation (object from Viktor SDK)?
At this moment we have to perform a new time consuming calculation for each visualization in the output views of our app.

Hey Enrique,

You can make use of the memoize but the Excel object itself cannot be memoized. You will have to make sure the input and ouput of the function is serializable. In most cases the Excel template as well as the Macro’s are static, so it will be safe to define those within the memoized function. Then only the input and output cells need to be serializable, something like this:

@memoize
def memoized_excel(serializable_input_cells: List[tuple]):
    named_input_cells = [NamedInputCell(*cell) for cell in serializable_input_cells]
    named_output_cells = [...]
    macros = [...]
    template = ...

    excel = Excel(template, named_input_cells=named_input_cells, macros=macros)
    excel.execute()

    # output should be serializable
    return {
        'output_x', named_output_cells[0].result,  # or excel.get_named_cell_result('output_x')
        'output_y', named_output_cells[1].result,  # or excel.get_named_cell_result('output_y')
        ...
    }

serializable_input_cells = [
    ('cell_1': 'value'),
    ('cell_2': 3),
    ...
]

result = memoized_excel(serializable_input_cells)


1 Like