[英]How to fix the problem of "'NoneType' object is not subscriptable."?
I am trying to conditionally select all the cells in the range in excel by python, but this shows every time.我试图通过python有条件地选择excel范围内的所有单元格,但这每次都会显示。
'NoneType' object is not subscriptable
Is there a way to fix it? 'NoneType' object is not subscriptable
有没有办法修复它?
I have already tried to put a str
around ws.cell(...)
, but it still does not work.我已经尝试在
ws.cell(...)
周围放置一个str
,但它仍然不起作用。
target_list = []
for i in range(1,20638):
for j in range(1,49):
if ws.cell(row = i, column = j).value[0:4] == "Drug":
target_list.append(ws.cell(row = i, column = j).value[5:])
else:
pass
I expect to select all the cells that begin with the word "Drug"
, but it shows '"'NoneType' object is not subscriptable'
every time.'我希望选择所有以单词
"Drug"
开头的单元格,但它每次都显示'"'NoneType' object is not subscriptable'
。
Just add a check before that line:只需在该行之前添加一个检查:
target_list = []
for i in range(1,20638):
for j in range(1,49):
if (ws.cell(row = i, column = j).value) is None:
continue
if ws.cell(row = i, column = j).value[0:4] == "Drug":
target_list.append(ws.cell(row = i, column = j).value[5:])
else:
pass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.