xlrd模块
1、通过xlrd模块读取Excel每行的内容
pyhton3安装xlrd模块:pip3 install xlrd
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
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)