def add_cells(sheet, sorted_dict, formats): conditional_formats = common.pop_dict(sorted_dict, "conditional_formats") column_sizes = common.pop_dict(sorted_dict, "column_size") for cell_pos, cell_value in sorted_dict.items(): new_value = InputFactory.get_args(cell_value, formats) new_key = InputFactory.parse_cell_position(cell_pos) args = new_key + new_value if isinstance(args[0], str) and ":" in args[0]: sheet.merge_range(*args) else: sheet.write(*args) XlsFactory.add_conditional_formats(conditional_formats, formats, sheet) XlsFactory.resize_columns(column_sizes, sheet)
def create(input): filename = common.pop_dict(input, "filename") workbook = Workbook(filename) formats = InputFactory.init_formats(input, workbook) for sheet in input['sheets']: XlsFactory.process_sheet(workbook, sheet, formats) workbook.close() return filename
def init_formats(input, workbook): return_dict = {} for k, v in common.pop_dict(input, "formats").items(): return_dict[k] = workbook.add_format(v) return return_dict