目录
1.安装xlrd3
pip install xlrd3
2.读取Excel文件内容
import xlrd3 as xlrd
# 实例化Excel对象
excel = xlrd.open_workbook('./副本.xlsx')
# 获取Excel中所有的sheet名
sheet_names = excel.sheet_names()
print("sheet_names", excel.sheet_names())
# 将一张sheet对象化
sheet1 = excel.sheet_by_name(sheet_names[0])
# 获取该sheet中的有效行和有效列的数量
nrows = sheet1.nrows
ncols = sheet1.ncols
print("nrows", nrows)
print("ncols", ncols)
# 获取该sheet的某一行的所有值,参数最大为nrows-1
print("行值", sheet1.row_values(0))
# 获取该sheet的某一列的所有值,参数最大为ncols-1
print("列值", sheet1.col_values(0))
# 用坐标值获取一个单元格的值,参数最大为(nrows-1,ncols-1)
print("单元格值", [sheet1.cell_value(0, col) for col in range(ncols)])
# 用坐标值获取一个单元格的数量类型,参数最大为(nrows-1,ncols-1)
print("单元格的数据类型", [sheet1.cell_type(0, col) for col in rang