菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
390
0

python怎么读取excel中的数值

原创
05/13 14:22
阅读数 37066

安装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中的数值的详细内容,更多请关注其它相关文章!

发表评论

0/200
390 点赞
0 评论
收藏
为你推荐 换一批