Python Forum
OpenPyxl Cell.value Alignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OpenPyxl Cell.value Alignment
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python code for alignment and font size 1418 0 311 Jan-14-2024, 03:56 AM
Last Post: 1418
  make all text in Right to left alignment in tkinter widgets jalal0034 1 1,318 Sep-27-2022, 06:42 PM
Last Post: Larz60+
  Right to left alignment in python report using Reportlab jalal0034 1 1,830 Sep-27-2022, 04:25 AM
Last Post: jalal0034
  pandas, tabulate, and alignment menator01 3 7,256 Feb-05-2022, 07:04 AM
Last Post: menator01
  Space between list and column alignment rturus 8 5,097 Mar-17-2021, 04:47 PM
Last Post: rturus
  How to append a value to specific excel cell using openpyxl hobbyist 0 4,835 Mar-05-2021, 07:14 PM
Last Post: hobbyist
  P3, openpyxl, csv to xlsx, cell is not number, problem with colorize genderbee 1 2,146 Sep-29-2020, 03:20 PM
Last Post: Larz60+
  openpyxl, if value in cell then change format genderbee 1 5,247 Nov-05-2019, 01:37 PM
Last Post: genderbee
  Need to copy column of cell values from one workbook to another with openpyxl curranjohn46 3 11,200 Oct-12-2019, 10:57 PM
Last Post: curranjohn46
  Data alignment in Python Nirmal 1 2,627 Feb-12-2019, 09:55 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020