网络编程
位置:首页>> 网络编程>> Python编程>> python3 读取Excel表格中的数据

python3 读取Excel表格中的数据

作者:qq_34500270  发布时间:2021-01-14 23:03:42 

标签:python,读取,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表格中的数据网站的支持!

来源:https://blog.csdn.net/qq_34500270/article/details/83089588

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com