python3 读取Excel表格中的数据
更新时间:2018年10月16日 15:49:30 作者:qq_34500270
这篇文章主要介绍了python3 读取Excel表格中的数据的相关资料,需要的朋友可以参考下
需要先安装openpyxl库
通过pip命令安装: pip install openpyxl
源码如下:
#!/usr/bin/python3 #-*- coding:utf-8 -*- import openpyxl def getCell(wb, sheetname, column): #指定读取哪个Sheet(每个excel表格默认有三个Sheet:Sheet1,Sheet2,Sheet3) table = wb[sheetname] #读取哪一列数据 cell = table[column] for c in cell: #过滤没有数据的行 if (c.value): #打印结果 print(c.value) if __name__ == "__main__": path = 'C:\\Users\\Desktop\\201808.xlsx' #excel对象 wb = openpyxl.load_workbook(path) print(wb.sheetnames) print(wb.active) #传入表名,第一个Sheet的名称 sheetname = wb.sheetnames[0] #传入列名,想读取哪一列就传入该列名 column = 'B' getCell(wb, sheetname, column)
总结
以上所述是小编给大家介绍的python3 读取Excel表格中的数据,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
相关文章
将FileStorage对象高效转换为NumPy数组的两种实现方案
在Web开发(如Flask应用)中,处理用户上传的图片文件时,常会遇到FileStorage对象向numpy.ndarray的转换需求,本文将提供两种经过验证的高效方法,并深入解析其技术细节与适用场景,需要的朋友可以参考下2025-03-03


最新评论