Correct way to align cell in python using openpyxl

What is the correct way to align text inside a cell? I tried this:

wrsheet.cell("B2").style.alignment.horizontal = "justify" 

But this gives me an error: warn ("Use formatting objects such as font directly")

+5
source share
1 answer

Excel styles are split between cells. To avoid unexpected side effects, you cannot change styles as soon as they should always be assigned to change. Since openpyxl v2.2 aggregate Style object is deprecated in favor of appropriate formatting objects such as Font, or in your case Alignment.

 from openpyxl.styles import Alignment ws['B2'].alignment = Alignment(horizontal="justify") 
+6
source

Source: https://habr.com/ru/post/1234925/


All Articles