python读取excel的行数

基于python3.x下

需要包

from openpyxl import load_workbook

代码如下:

 from openpyxl import load_workbook
wb = load_workbook(filename=r'C:\\Users\\Administrator\\Desktop\\库存大表0803.xlsx') ##读取路径
ws = wb.get_sheet_by_name("Sheet1") ##读取名字为Sheet1的sheet表
num = 1 while 1:
cell = ws.cell(row=num, column=1).value
if cell:
num = num +1
else:
print(num)
exit()

其中,设置了死循环

while 1:

则一直读取单元格的内容:

cell = ws.cell(row=num, column=1).value

如果cell不为空

if cell:
num = num +1

则继续读取下一行

如果出现空,那么打印num的值,也就是行数,最后跳出程序

else:
print(num)
exit()
上一篇:SSM框架--Spring+SpringMVC+Mybatis (IDEA)搭建


下一篇:RMAN-06217: not connected to auxiliary database with a net service name