Python Openpyxl library cannot deal with automatic row height
I'm currently using Openpyxl in a Django project to create an excel report. I'm starting from a blank excel model in which column C has text wrap enabled. Infact when I open the model and populate manually a cell I correctly get this
But when I run this trial code
wb = openpyxl.load_workbook(fileExcel)
sh = wb["Rapportini"]
sh["C3"]="very very very very very very very very very very long row"
wb.save(fileExcel)
this is the result
I know openpyxl (strangely) cannot set row autoheight. I also tried to set wrap_text = True in the cell, but no way... any ideas ?
With the openpyxl.styles.Alignment
module, you can wrap text in a specific cell (i.e C3
).
Try this :
wb = openpyxl.load_workbook(fileExcel)
sh = wb["Rapportini"]
sh["C3"].value = "very very very very very very very very very very long row"
sh["C3"].alignment = openpyxl.styles.Alignment(wrap_text=True)
sh.column_dimensions["C"].width = 20
wb.save(fileExcel)
Output :