【Python&知识点】Python读取excel(xlrd模块)

外部链接:https://www.cnblogs.com/zhang-jun-jie/p/9273721.html

        https://www.cnblogs.com/lhj588/archive/2012/01/06/2314181.html

1、打开文件夹

x1 = xlrd.open_workbook("data.xlsx")

2、获取sheet

x1.sheet_names()#获取所有sheet的名字
x1.nsheets#获取sheet数量
x1.sheets()#获取所有的sheet数量
x1.sheet_by_name('test')#通过sheet名查找
x1.sheet_by_index(3)#通过索引查找

3、获取sheet的汇总数据

sheet1.name#获取sheet名
sheet1.nrows#获取总行数
sheet1.ncols#获取总列数

4、行操作

sheet1.row_values(0)  # 获取第一行所有内容,合并单元格,首行显示值,其它为空。
sheet1.row(0)           # 获取单元格值类型和内容
sheet1.row_types(0)   # 获取单元格数据类型

5、表操作

sheet1.row_values(0, 6, 10)   # 取第1行,第6~10列(不含第10表)
sheet1.col_values(0, 0, 5)    # 取第1列,第0~5行(不含第5行)
sheet1.row_slice(2, 0, 2)     # 获取单元格值类型和内容
sheet1.row_types(1, 0, 2)   # 获取单元格数据类型

·

·

·

·

·

猜你喜欢

转载自www.cnblogs.com/jason-syc/p/11245717.html