Skip to content Skip to sidebar Skip to footer

How To Check If A Cell Is Empty In Openpyxl Python

I'm making a conditional statement in openpyxl Python to check if a cell is empty. Here's my code: newlist = [] looprow = 1 print ('Highest col',readex.get_highest_column()) ge

Solution 1:

You compare prevsymbol with str "None", not None object. Try

ifprevsymbol== None:

Also here

prevsymbol = readex.cell(row = looprow,column=getnewhighcolumn).value

you use looprow as row index. And you increment looprow only if cell.value is not empty. Here

newstocks.append(prevsymbol)

you use newstocks instead of newlist. Try this code

newlist = []
print ("Highest col",readex.get_highest_column())
getnewhighcolumn = readex.get_highest_column()        
for i inrange(0, lengthofdict):
    prevsymbol = readex.cell(row = i+1,column=getnewhighcolumn).value
    if prevsymbol isnotNone:
        newlist.append(prevsymbol)
print(newlist)

Solution 2:

Take the quotes away from the None.

if prevsymbol isNone:

This is the python equivalent of checking if something is equal to null.

Post a Comment for "How To Check If A Cell Is Empty In Openpyxl Python"