您好,欢迎访问一九零五行业门户网

python怎么读取excel中的数值

最近测试过程中需要用到python读取excel用例数据,于是去了解和学习了下xlrd库,这里只记录使用过程中读取excel数据相关操作。
安装xlrd库(推荐学习:python视频教程)
可以下载xlrd库包到本地安装,也可以通过pip命令安装,这里我选择pip命令:
pip install xlrd
使用xlrd读取excel数据
具体详细的操作可以参考xlrd库操作说明文档,以下是两种读取excel数据的方法:
根据excel中sheet名称读取数据:
 import xlrddef readexceldatabyname(filename, sheetname):    table = none    errormsg = none    try:        data = xlrd.open_workbook(filename)        table = data.sheet_by_name(sheetname)    except exception, msg:        errormsg = msg      return table, errormsg
根据excel中sheet的序号获取:
 import xlrddef readexceldatabyindex(filename, sheetindex):    table = none    errormsg =     try:        data = xlrd.open_workbook(filename)        table = data.sheet_by_index(sheetindex)    except exception, msg:        errormsg = msg    return table, errormsg
更多python相关技术文章,请访问python教程栏目进行学习!
以上就是python怎么读取excel中的数值的详细内容。
其它类似信息

推荐信息