What is the proper way to align text inside cell? I tried this:
wrsheet.cell("B2").style.alignment.horizontal = "justify"
But it gives me an error: warn("Use formatting objects such as font directly")
In Excel styles are shared between cells. To avoid unexpected side-effects you cannot modify styles once they must always been assigned to be changed. Since openpyxl v2.2 the aggregate Style object is deprecated in favour of the relevant formatting objects such as Font, or in your case Alignment.
from openpyxl.styles import Alignment
ws['B2'].alignment = Alignment(horizontal="justify")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With