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

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")
        cell_color=IN_sht.cell(row = i, column=1).fill.start_color.index
        print(str(i) + "Blank" + str(cell_color))

Possibly Related Threads…
Thread Author Replies Views Last Post
  Find last filled column in openpyxl Irv1n 2 230 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 9,413 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 3,137 Feb-11-2021, 09:31 PM
Last Post: nilamo
  Openpyxl tkinter search a value in Excel column Heathcliff_1 0 1,349 Dec-02-2020, 04:35 PM
Last Post: Heathcliff_1
  Using OpenPyXL How To Read Entire Column Into Dictionary jo15765 1 1,284 Jun-08-2020, 04:10 AM
Last Post: buran
  Check for a special characters in a column and flag it ayomayam 0 930 Feb-12-2020, 03:04 PM
Last Post: ayomayam
  Unable to write to excel - Using openpyxl module starstud 2 2,086 Feb-05-2020, 03:53 AM
Last Post: starstud
  python openpyxl writing data Bikram 2 1,295 Oct-17-2019, 03:33 PM
Last Post: Bikram
  Need to copy column of cell values from one workbook to another with openpyxl curranjohn46 3 7,649 Oct-12-2019, 10:57 PM
Last Post: curranjohn46
  Openpyxl -Coming up with a single column from a multi column data set Givan007 1 1,661 Sep-07-2018, 04:29 AM
Last Post: Prabakaran141

Forum Jump:

User Panel Messages

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