2019-03-01
阅读量:
660
python如何使用Openpyxl处理excel数据
Openpyxl是python中用于读取和编写Excel文件的Python库,用户可能必须经历数千行并挑选少量信息以根据某些标准进行小的更改。使用Openpyxl模块,可以非常高效,轻松地完成这些任务。
使用此命令安装openpyxl 模块:
sudo pip3 install openpyxl # import openpyxl module
import openpyxl
# Give the location of the file
path = "C:\\Users\\Admin\\Desktop\\demo.xlsx"
# to open the workbook
# workbook object is created
wb_obj = openpyxl.load_workbook(path)
sheet_obj = wb_obj.active
代码#2:确定总行数
print(sheet_obj.max_row)
代码#3:确定总列数
print(sheet_obj.max_column)
代码#4:打印所有列名称
for i in range(1, max_col + 1):
cell_obj = sheet_obj.cell(row = 1, column = i)
print(cell_obj.value)
17.9321
1
2
关注作者
收藏
评论(0)
发表评论
暂无数据
推荐帖子
0条评论
0条评论
0条评论

