Python Forum
Python Openpyxl is unable to check from Column 6 onwards
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Openpyxl is unable to check from Column 6 onwards
#1
Hi,

I want to use Openpyxl to check if cells.value='OK' and the interior color of its corresponding row in another sheet is !='FF9BCCFF'. I used the code appended at the end. It works fine for Column 1 to 5 in

R_sht.cell(row = i, column=7).value=='OK'
But when I change to column 6 onwards the code doesn't work. It goes to else block although I have rows that meet the criteria of if block.

I even tested by copying and pasting column 5 to column 6. So both columns have SAME contents/format/etc. And the code works on column 5 but fails in column 6.

I am not sure why there is this issue. I tried on 2 different Excel workbooks. Same issue. Code fails for column 6 onwards.

There is no upload function here for me to show a sample workbook.

But hope someone can still help. Thank you
for i in range (first_used_row,last_used_row+1):
 
    if R_sht.cell(row = i, column=7).value=='OK' and IN_sht.cell(row = i, column=1).fill.start_color.index!='FF9BCCFF':
        print(str(i) + "Not Blank")
    else:
        cell_color=IN_sht.cell(row = i, column=1).fill.start_color.index
        print(str(i) + "Blank" + str(cell_color))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [sqilte3] Check if column not empty? Winfried 5 1,066 Jan-28-2023, 12:53 PM
Last Post: Winfried
  Reshaping a single column in to multiple column using Python sahar 7 1,968 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  Openpyxl-change value of cells in column based on value that currently occupies cells phillipaj1391 5 9,573 Mar-30-2022, 11:05 PM
Last Post: Pedroski55
  Find last filled column in openpyxl Irv1n 2 12,554 Jan-16-2022, 11:05 AM
Last Post: Pedroski55
  OpenPyxl: How to iterate through each Column (in 1 row) to find a value? chatguy 2 17,842 Apr-06-2021, 04:52 AM
Last Post: carlhyde
  How can I iterate through all cells in a column (with merge cells) with openpyxl? aquerci 1 7,445 Feb-11-2021, 09:31 PM
Last Post: nilamo
  Openpyxl tkinter search a value in Excel column Heathcliff_1 0 3,212 Dec-02-2020, 04:35 PM
Last Post: Heathcliff_1
  Using OpenPyXL How To Read Entire Column Into Dictionary jo15765 1 2,642 Jun-08-2020, 04:10 AM
Last Post: buran
  Unable to install python-wnck python-imaging on Void Linux linuxlight 1 3,152 Mar-08-2020, 03:53 AM
Last Post: Larz60+
  Check for a special characters in a column and flag it ayomayam 0 2,017 Feb-12-2020, 03:04 PM
Last Post: ayomayam

Forum Jump:

User Panel Messages

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