Skip to main content

Spreadsheet templater


Services need to be mocked within the context of (automated) testing.

This guide will assume the template (represented by bytes) is available. Either named cells (cells which can be found using a certain key) or direct cells (cell which can be found by a direct address {sheet, column, row}) can be used to fill the template.

An example implementation of how a spreadsheet template can be filled can be found below.

from viktor.external.spreadsheet import NamedInputCell, DirectInputCell, render_spreadsheetcells = [    DirectInputCell('sheet1', 'A', 1, 5),    NamedInputCell('named_cell_1', 'text_to_be_placed'),]template_path = Path(__file__).parent / 'my' / 'relative' / 'path' / 'template.xlsx'with open(template_path, 'rb') as template:    filled_spreadsheet = render_spreadsheet(template, cells)

When large blocks of cells need to be filled, an InputCellRange can be used.