前言
xlrd模块安装
pip install xlrd
xlrd常用方法
1、导入模块
import xlrd
2、打开文件
x1 = xlrd.open_workbook("data.xlsx")
3、获取sheet
获取所有sheet名字:x1.sheet_names()
获取sheet数量:x1.nsheets
获取所有sheet对象:x1.sheets()
通过sheet名查找:x1.sheet_by_name("test”)
通过索引查找:x1.sheet_by_index(3)文章来源:https://www.toymoban.com/news/detail-511461.html
# -*- coding:utf-8 -*-
import xlrd
import os
filename = "demo.xlsx"
filePath = os.path.join(os.getcwd(), filename)
print(filePath)
# 1、打开文件
x1 = xlrd.open_workbook(filePath)
# 2、获取sheet对象
print 'sheet_names:', x1.sheet_names() # 获取所有sheet名字
print 'sheet_number:', x1.nsheets # 获取sheet数量
print 'sheet_object:', x1.sheets() # 获取所有sheet对象
print 'By_name:', x1.sheet_by_name("test") # 通过sheet名查找
print 'By_index:', x1.sheet_by_index(3) # 通过索引查找
输出:文章来源地址https://www.toymoban.com/news/detail-511461.html
sheet_names: [u' plan', u'team building', u'modile', u'test']
sheet_number: 4
sheet_object: [<xlrd.sheet.Sheet object at 0x10244c190>, <xlrd.sheet.Sheet object at 0x10244c150>, <xlrd.sheet.Sheet object at 0x10244c110>, <xlrd.sheet.Sheet object at 0x10244c290>]
By_name: <xlrd.sheet.Sheet object at 0x10244c290>
By_index: <xlrd.sheet
到了这里,关于Python自动化测试,Excel数据驱动读取 xlrd实战(超详细)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!