I have two sheets in an Excel file and the first one is a cover sheet which I don\'t need to edit. There are a few merged cells in the cover sheet, and when I edit the file usin
For me this code work perfectly:
wb = load_workbook(template_path)
ws = wb.active
for merged_cells in ws.merged_cells.ranges:
style = ws.cell(merged_cells.min_row, merged_cells.min_col)._style
for col in range(merged_cells.min_col, merged_cells.max_col + 1):
for row in range(merged_cells.min_row, merged_cells.max_row + 1):
ws.cell(row, col)._style = style
I simply find all merged cells and apply style of left top cell to the rest of the cells.