How to check every cell from a column in an excel sheet?

Viewed 435

I am struggling to find a way to solve my problem. I have an excel file which has data. I need to check the type of data in columns (with every cell).

enter image description here

For example, in this column, I need to check that every cells are strings. But as you can see, there is a cell that is an int. In this situation, I need to write this line in a new text file.

This is the code I have so far :

from openpyxl import load_workbook

book = load_workbook('export.xlsx')
sheet = book['Data']

for row in sheet.rows:
    print (str(row[6].value))
    

Thanks for any help !

1 Answers

For this special case you may try this:

intList = list()
for row in sheet.rows:
    try:
        intList.append(int(row[6].value))
    except:
        pass

It will try to get the int value of the cell, and if it succeeded, it will push it into a list

Related