Python Forum

Full Version: OpenPyxl Cell.value Alignment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I am using OpenPyXl and need to align different cells with different alignment values (center, right, bottom, etc.). My code seems to be ignoring my if statements. The center alignment is working.
Any clue what's wrong with the If statement? (I've also tried this:
if sheet['A1':'I43'] == 'Hz':
)

# Cell Alignment
al = Alignment(horizontal='center', vertical='center')
br = Alignment(horizontal='right', vertical='bottom')
for row in sheet['A1':'I43']: 
        for cell in row: 
            if cell == 'Hz':
                cell.alignment = br
            else:
                cell.alignment = al
Thanks,
Phil