column_widths = [] for row in data: for i, cell in enumerate(row): iflen(column_widths) > i: iflen(cell) > column_widths[i]: column_widths[i] = len(cell) else: column_widths += [len(cell)]
for i, column_width in enumerate(column_widths): worksheet.column_dimensions[get_column_letter(i+1)].width = column_width