jeudi 4 février 2021

How to read data from excel sheet with if else statement in for loop Python

                for i in range(j, k):
                    if currentSheet["D" + str(i)].value == codein:
                        c = currentSheet["D" + str(i)].value
                        print("Code Found", c)
                        
                    elif currentSheet["D" + str(i)].value != codein:
                        ac = currentSheet["D" + str(i)].value
                        #print("Availables", ac)
                        if currentSheet["E" + str(i)].value:
                            f = currentSheet["E" + str(i)].value
                            if c0 != f:
                                if currentSheet["F" + str(i)].value:
                                    m = currentSheet["F" + str(i)].value
                                    if c1 == m:
                                        if currentSheet["G" + str(i)].value:
                                            l = currentSheet["G" + str(i)].value
                                            if c2 == l:
                                                print(ac)
                                                
                            elif c0 == f:
                                if currentSheet["F" + str(i)].value:
                                    m = currentSheet["F" + str(i)].value
                                    if c1 != m:
                                        if currentSheet["G" + str(i)].value:
                                            l = currentSheet["G" + str(i)].value
                                            if c2 == l:
                                                print(ac)
                                                
                                    elif c1 == m:
                                        if currentSheet["G" + str(i)].value:
                                            l = currentSheet["G" + str(i)].value
                                            if c2 != l:
                                                print(ac)
                    
                                

Assume all the codes are read from an excel sheet. I want the output to be like Code Found A3L when if statement is ok and

Available Code B7W Available Code U8I 

when the else statement is ok. But the problem is both the Found code and Available codes are out coz if else is in loop. Request any better solution for this problem.

Aucun commentaire:

Enregistrer un commentaire