def openxyl_row_copy(ws, row, strike=False): copied_row = [] for cell in row: new_cell = Cell(ws, value=cell.value) new_cell.style = copy(cell.style) new_cell.font = new_cell.font + Font(strike=strike) copied_row.append(new_cell) return copied_row
def apply_formatting(data): logger.info('Matching formatting to worksheet') for d in data: d = Cell(ws, column='A', row=1, value=d) d.font = Font(name='Calibri', size=9) d.alignment = Alignment(horizontal='center', vertical='center', wrap_text=True) yield d
def format_line(line, type): size = size_dict[type] for c in line: c = Cell(ws, value=c) c.font = Font(bold=True, size=size) yield c
sheet_name=None) locations.append([mia_file, 'MIA']) except FileNotFoundError: print('No MIA') if not locations: continue order = [ 'EE Status', 'Delays Cancellations', 'Aircraft in Work', 'Training', 'Events' ] wb = openpyxl.Workbook() ws = wb.active ws.title = 'Morning Report' date_cell = Cell(ws, value='Morning Report: ' + date) date_cell.font = Font(bold=True, size=14) ws.append([date_cell]) ws.append([]) cols = ['A', 'B', 'C', 'D', 'E'] widths = [21, 12, 20, 24, 24] for df_dict, loc in locations: ws.append(format_line([loc + ' Line Maintenance Operations'], 'header')) for sheet in order: df = df_dict[sheet] ws.append(format_line([sheet], 'title')) if sheet == 'Events': df = df.set_index('Customer') df = remove_excess(df) df = df.replace(0, np.nan) df = df.reset_index()