Skip to content

Instantly share code, notes, and snippets.

@arvsr1988
Created July 21, 2020 10:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arvsr1988/4468e7f9bb9c5f3aa514eea6a14804b6 to your computer and use it in GitHub Desktop.
Save arvsr1988/4468e7f9bb9c5f3aa514eea6a14804b6 to your computer and use it in GitHub Desktop.
#auto adjusting column width of cells for openpyxl 3.0
for column_cells in ws.columns:
unmerged_cells = list(filter(lambda cell_to_check: cell_to_check.coordinate not in ws.merged_cells, column_cells))
length = max(len(str(cell.value)) for cell in unmerged_cells)
ws.column_dimensions[unmerged_cells[0].column_letter].width = length * 1.2
@nanltech
Copy link

nanltech commented Nov 8, 2021

Thank You.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment