安装xlrd模块
pip install xlrd
或者去官网下载
使用
读取文件
file = xlrd.open_workbook("./sample.xlsx")
此时file是整个文件对象,获取某个工作表可以用序号或者表名
- 序号获取
sheet0 = file.sheet_by_index(0)
sheet1 = file.sheet_by_index(1)
- 表名基本信息
sheet_1 = file.sheet_by_name("Sheet1")
print("表名:\t" ,sheet_1.name)
print("表行数:\t",sheet_1.nrows)
print("表列数:\t",sheet_1.ncols)
表名: Sheet1
表行数: 4
表列数: 3
读取某个单元格内容
row = 1
col = 2
print("第{}行 第{}列: {}".format(row,