1、通过xlrd模块读取Excel每行的内容
pyhton3安装xlrd模块:pip3 install xlrd
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 import xlrd 2 filepath='xxxxx.xlsx' # 文件路径 3 sheet = xlrd.open_workbook(filepath) #获得sheet对象 4 5 for sheet_name in sheet.sheet_names(): 6 sheet2 = sheet.sheet_by_name(sheet_name) 7 for row in range(0,sheet2.nrows): 8 rows = sheet2.row_values(row) 9 print(rows)
sheet = xlrd.open_workbook(filepath)
sheet.sheet_names()#获取Excel的所有的sheet的名字
sheet._sheet_names #获取Excel的所有的sheet的名字
sheet._sheet_list #获取sheet对象
sheet2=sheet.sheet_by_name(sheet_name)通过sheet名称huozi
sheet2.nrows
sheet2.name
sheet2.ncols
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 sheet = xlrd.open_workbook(filepath) 2 for sheet2 in sheet._sheet_list: 3 for row in range(0,sheet2.nrows): 4 rows = sheet2.row_values(row) 5 print(rows)