mardi 15 juin 2021

Openpyxl cell value differs inside a loop. If statement doesn't restrict access

I am trying to iterate through all the lines in an excel document and remove the entries that start with Deleted or Cancelled

The issue i have is that in the 4th line print(...) returns the value i expect. But when the exact same line is used in the if statement everything is simultaneously == and != to 'Dele' & 'Canc'.

Furthermore, when printed again in the loop, everything returns None. This includes every other cell in every row.

Why is the IF statement preventing nothing? and why is the value always None after the loop begins

S_Row = S_sheet.max_row
print(str(S_sheet['C' + str(S_Row)].value)[0:4])
for S_Row in range(2, S_sheet.max_row):
    if str(S_sheet['C' + str(S_Row)].value[0:4]) == 'Dele' or 'Canc':

max row is 466 which is also just shy of the actual max row. any help will be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire