教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 python怎么读取excel中的数值

python怎么读取excel中的数值

发布时间:2020-10-30   编辑:jiaochengji.com
教程集为您提供python怎么读取excel中的数值等资源,欢迎您收藏本站,我们将为您提供最新的python怎么读取excel中的数值资源
最近测试过程中需要用到python读取excel用例数据,于是去了解和学习了下xlrd库,这里只记录使用过程中读取excel数据相关操作。

安装xlrd库(推荐学习:Python视频教程)

可以下载xlrd库包到本地安装,也可以通过pip命令安装,这里我选择pip命令:

pip install xlrd

使用xlrd读取excel数据

具体详细的操作可以参考xlrd库操作说明文档,以下是两种读取excel数据的方法:

根据Excel中sheet名称读取数据:  

 import xlrd
def 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 xlrd
def 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中的数值的详细内容,更多请关注教程集其它相关文章!

  • 本文原创发布教程集,转载请注明出处,感谢您的尊重!
  • 您可能感兴趣的文章:
    python怎么读取excel中的数值
    python怎么读写excel文件
    python怎么读取和写入excel表格
    在C#.net 中读取EXCEL文件的数据
    python怎么读excel
    python怎么读取excel表格
    python如何对excel数据进行处理
    php框架laravel excel包使用教程介绍
    python怎么连接excel
    Python新手入门:Excel基本操作(一)

    [关闭]
    ~ ~