打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
接口测试基础——第5篇xlrd模块
# coding: utf-8

import xlrd

# excel路径
excel_path = r'C:\Users\weiming\Desktop\Inter\data\test_case_merchant_basic.xlsx'

# 打开Excel
data = xlrd.open_workbook(excel_path)

# 查看Excel中的sheet名称
data.sheet_names()
# 通过索引或表名获取第一个工作表:一个list
table = data.sheets()[0]
# table1 = data.sheet_by_index(0)
# table2 = data.sheet_by_name(u'部门管理')
# print table, table1, table2
# 获取行数和列数
nrows = table.nrows
ncols = table.ncols
# print nrows, ncols
# 获取整行和整列的值
# print table.row_values(1)
# print table.col_values(2)
# 循环行,得到索引的列表
# for rn in range(table.nrows):
    # print table.row_values(rn)

# 单元格
cell_A1 = table.cell(0, 0).value
cell_A2 = table.cell(1, 0).value
# print cell_A1, cell_A2

# 分别使用行列索引
cell_A3 = table.row(0)[0].value
cell_A4 = table.col(1)[1].value
print cell_A3, cell_A4

接口测试经常需要操作Excel表格,以上就是读Excel的常用方法,大家多写写,记住了以后用起来就方便了。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
python3读取excel文件只提取某些行某些列的值
Python读写Excel文件的实例
一文看懂用Python读取Excel数据
【python】解析Excel中使用xlrd库、xlwt库操作,读取excel进阶完整脚本实例(四)
python:利用xlrd模块操作excel
UC头条:编程小白的自学笔记二(用python处理表格文件)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服