比来测试进程中需求用到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 python教程 python编程 python使用问题
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!