Python Forum

Full Version: Python Openpyxl is unable to check from Column 6 onwards
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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))