Openpyxl check for empty cell

To do something when cell is not empty add:

if cell.value:

which in python is the same as if cell value is not None (i.e.: if not cell.value == None:)

Note to avoid checking empty cells you can use

worksheet.get_highest_row()

and

worksheet.get_highest_column()

Also I found it useful (although might not be a nice solution) if you want to use the contents of the cell as a string regardless of type you can use:

unicode(cell.value)

Leave a Comment