python——xlrd库使用

Table of Contents

什么是xlrd库?
使用python去对excel表格进行操作的时候主要用到xlrd和xlwt这两个库

xlrd库安装:

python——xlrd库使用 

python——xlrd库使用 

python——xlrd库使用

 python——xlrd库使用

python——xlrd库使用

python——xlrd库使用

python——xlrd库使用

python——xlrd库使用

 xlrd是读取excel,xlwt是写入excel


———————————————–xlrd库函数—————————————————–
打开文件
x1 = xlrd.open_workbook(filename)

获取sheet对象
x1.sheet_names()           # 获取所有sheet名字
x1.nsheets                     # 获取sheet数量
x1.sheets()                     # 获取所有sheet对象
x1.sheet_by_name("test")      # 通过sheet名查找
ds = x1.sheet_by_index(3)      # 通过索引查找 

获取sheet的汇总数据
ds.name           #获取sheet名
ds.nrows          #获取总行数
ds.ncols           #获取总列数

行操作
ds.row_values(0)      #获取第一行所有内容
ds.row(0)             #获取单元格值类型和内容
ds.row_types(0)        #获取单元格数据类型

表操作
ds.row_values(0,6,10)      #取第一行,第6-9列
ds.col_values(0,0,5)         #取第一列,第0-4行
ds.row_slice(2,0,2)           #获取单元格值类型和内容,同sheet1.row()
sheet1.row_types(1,0,2)   #获取单元格数据类型

特定单元格读取或获取单元类型
ds.cell_value(1,2)
ds.cell(1,2).value
ds.row(1)[2].value
ds.cell(1,2).ctype
ds.cell_type(1,2)
ds.row(1)[2].ctype

单元格位置表达方式
xlrd.cellname(0,0)          #将(0,0)转化为A1
xlrd.cellnameabs(0,0)   #将(0,0)转化为SAS1
xlrd.colname(30)          #将列由数字转换为字母表示


数据类型:
空:0
字符串:1
数字:2
日期:3
布尔:4
error:5

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
xiaoxingxing的头像xiaoxingxing管理团队
上一篇 2023年3月6日
下一篇 2023年3月6日

相关推荐

此站出售,如需请站内私信或者邮箱!