Created
July 21, 2020 10:27
-
-
Save arvsr1988/4468e7f9bb9c5f3aa514eea6a14804b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank You.