Python/Openpyxl - comparing cells in excel with diff format (text vs number)

Viewed 43

Good day.

I would like to compare 2 cells in excel using python/openpyxl. And Im using simple below formula.

x=1
print(ws.max_column,ws.max_row)
for i in range(1,ws.max_column):
    for j in range(3,ws.max_row+1):
        y=x+1
        if ws.cell(j,x).value != ws.cell(j,y).value:
            print("Errors found: ")
            print(ws.cell(j,x), ws.cell(j,x).value, ws.cell(j,y).value)
            print(ws.cell(j,x).style)
            print(ws.cell(j,y).style)
    x+=2

Issue is the result Im getting for printout:

Errors found: 
<Cell 'Sheet1'.S228>  None

Normal

Normal

I cant find a reason why he reports a difference when both cells in excel are blank.

Thank you upfront

1 Answers

Update:

Ok I found a way if someone encounters the same problem. Half-hearted solution - LINK

So I used kutools and used function "To Actual" that made all blank but not blank cells to blank ones.

Full answer would be to find a way to do the same with openpyxl. This is the answer Im still looking for.

Related