一、概述
python操作excel各个库对比:https://www.cnblogs.com/paul-liang/p/9187503.html
官方文档:https://openpyxl.readthedocs.io/en/stable/#usage-examples
二、入门
1.安装:
pip install openpyxl
conda:
conda install openpyxl
2.创建excel文件
from openpyxl import Workbook # 实例化一个工作簿 wb = Workbook() # 激活工作簿 ws = wb.active
3.打开已有文件
from openpyxl import load_workbook wb2 = load_workbook('文件名称.xlsx')
4.单元格赋值
ws['A1'] = 42
5.单元格访问
c = ws['A4'] d = ws.cell(row=4, column=2, value=10)
6.保存文件
wb.save('文件名称.xlsx')
更多参考:https://blog.csdn.net/weixin_43094965/article/details/82226263