美文网首页
python xlrd读取和操作excel的常用方法

python xlrd读取和操作excel的常用方法

作者: 史蒂夫sdf | 来源:发表于2020-09-23 09:41 被阅读0次

安装xlrd模块(cmd命令)

pip install xlrd

引入xlrd模块和读取本地excel

import xlrd
book = xlrd.open_workbook('./test.xlsx')

常用方法

for i in book.sheet_names(): #读取excel每页的名字
    sheet = book.sheet_by_name(i) #读取指定页
    sheet.row_values(0) #行数组
    sheet.nrows #行数
    sheet.col_values(0) #列数组
    sheet.ncols #列数
    sheet.cell(0,0) #指定位置
    sheet.cell(0,0).ctype #单元格类型0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error

参考:
python里面的xlrd模块详解(一)

相关文章

网友评论

      本文标题:python xlrd读取和操作excel的常用方法

      本文链接:https://www.haomeiwen.com/subject/arnwyktx.html