Форум сайта python.su
class Excel: def __init__(self) -> None: self.wb = xl.Workbook() del self.wb['Sheet'] self.consolas = NamedStyle(name='Consolas') self.consolas.font = Font(name='Consolas', size=10) self.consolas.alignment = Alignment(horizontal='center',vertical='center') # self.wb.active # self.file_name = 'unknown.xlsx' def file_exist(self, wb_name, ws_name): # проверяет на существование файла if os.path.isfile(wb_name) is True: # если файл существует self.wb = load_workbook (wb_name) # то загружает его if ws_name in self.wb: self.wb.active else: self.wb.create_sheet(ws_name, 0) self.wb.active else: self.wb.create_sheet(ws_name, 0) self.wb.active self.wb.save(wb_name) return self.wb.save(wb_name) def last_column(self, wb_name, ws_name): self.wb = load_workbook (wb_name) self.ws = self.wb[ws_name] self.last_row = self.ws.max_row self.last_col = self.ws.max_column return self.last_col def col_writer(self, data_hat, data_meas, wb_name, ws_name): self.wb = load_workbook (wb_name) self.ws = self.wb[ws_name] self.last_row = self.ws.max_row self.last_col = self.ws.max_column for c_index, col in enumerate(data_hat, start=self.last_col+1): self.wb[ws_name].column_dimensions[get_column_letter(c_index)].width = 20 for r_index, row in enumerate(col, start=1): self.wb[ws_name].cell(r_index, c_index, row) for c_index, col in enumerate(data_meas, start=self.last_col+1): for r_index, row in enumerate(col, start=11): self.wb[ws_name].cell(r_index, c_index, row) return self.wb.save(wb_name)
Офлайн