在线英文教程https://openpyxl.readthedocs.io/en/stable/tutorial.html
1]openxl的安装 https://jingyan.baidu.com/article/6f2f55a1ef0b87f4b83e6c3a.html
pip install openpyxl
如果不成功,进入D:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\Scripts\openpyxl
python3 setup.py install
2]openxl的使用https://www.cnblogs.com/programmer-tlh/p/10461353.html
3]import datatime
ws['A3'] = datetime.datetime.now().strftime("%Y-%m-%d")
4]load_workbook加载已有
from openpyxl import load_workbook wb = load_workbook('openpyxl.xlsx')
5]单元格样式。colors属性
# -*- coding: cp936 -*- import datetime from openpyxl import load_workbook wb = load_workbook('openpyxl.xlsx') ws = wb.active from openpyxl.styles import Font, colors, Alignment ws['A1']='sadfsdfasdf' ws['A1'].font = Font(name='等线', size=24, italic=True, color="FFFF00", bold=True)
ws['B1'].alignment = Alignment(horizontal='center', vertical='center')#对齐方式,除了center,还可以使用right、left
等等参数 wb.save('文件名称.xlsx')
6]一句话读单元格的值
import openpyxl c = openpyxl.load_workbook('openpyxl.xlsx').worksheets[0]['a1'].value
from openpyxl import load_workbook wb = load_workbook('openpyxl.xlsx') ws1 = wb["Sheet1"] astr='ABCDEFGHIJK' for i in astr: for j in range(1,10): if (astr.index(i)+1)==j: ws1[i+str(j)]=i+str(j) wb.save('openpyxl.xlsx')