samedi 25 juin 2016

How to stop printing using if statement with openpyxl

I'm reading values from an excel workbook and I'm trying to stop printing when the value of a specific cell equals a string. Here is my code

import openpyxl
    wb = openpyxl.load_workbook('data.xlsx')
    for sheet in wb.worksheets:
        nrows = sheet.max_row
        ncolumns = sheet.max_column
        for rowNum in range(20,sheet.max_row):
            Sub = sheet.cell(row=rowNum, column=3).value
            Unit = sheet.cell(row=rowNum, column=6).value
            Concentration = sheet.cell(row=rowNum, column=9).value
            com = rowNum[3]
            if Sub == "User:":
                pass
            else:
                print  Sub, Concentration, Unit

The problem is that the if statement doesn't work. When I use type(Sub), python return

Do you have any idea how to do it ?

Thanks

Aucun commentaire:

Enregistrer un commentaire