Checking for empty cells with OpenPyXl

旧城冷巷雨未停 提交于 2019-12-06 07:19:36

What Charlie mentions is of course correct.

Non empty strings in Python evaluate to True, so you are actually testing if cell value is None or if bool('None'), and the later is always True, hence your condition always evaluates to True.

To address your specific case I'm not sure why you are trying to test for an empty cell with 'None'.

In case you really want to do this your condition should look like this:

if sheet.cell(row=i, column=1).value in [None,'None']

If you want test for None or an empty string, so None or '' then of course your condition should be:

if sheet.cell(row=i, column=1).value in [None,'']

Hope this gets you on the right track..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!