现在我使用for循环来检测excel文件中的空单元格。找到空白单元格时需要停止循环。但是我的循环无法停止工作。找到空白单元格时我需要中断循环。
这是我的代码:
for i in excel:
if i == None:
print('Finish work')
break
elif i == '1':
py.hotkey('Enter')
else:
py.hotkey('Enter','Tab')
py.hotkey('tab');py.hotkey('tab');py.hotkey('tab');py.hotkey('tab');py.hotkey('tab');py.hotkey('tab')
这是我的excel文件图像:
This's my excel File picture i don't have reputation score i can't post picture.
最佳答案
您可以使用pylightxl轻松完成此操作。如果您正在做的只是读取数据(请参阅文档:https://pylightxl.readthedocs.io/en/latest/quickstart.html)
import pylightxl as xl
db = pylightxl.readxl('yourExcelFile.xlsx')
# assuming your data is in Sheet1 and column A (you can change this to whatever you need)
for celldata in db.xl('Sheet1').col(1):
if celldata == '':
print('Finish work')
break
elif celldata == '1':
# do something
pass
else:
# do something else
pass