1-openpyxl基础用法
2-openpyxl单元格样式处理
3-openpyxl日期格式处理
4-openpyxl单元格合并
5-openpyxl批量操作单元格
6-openpyxl数字格式处理
openpyxl 单元格样式处理
from openpyxl.styles import Font, PatternFill, Border, Side, Alignment, Color
from openpyxl import load_workbook
dest_filename = 'data.xlsx'
wb = load_workbook(filename=dest_filename)
sheet1 = wb['first sheet']
sheet1['B6'].font = Font(color='FF00FF', size=12, name='隶书', bold=True, underline='double', strike=True)
sheet1['B6'].value = '样式处理'
sheet1['A1'].fill = PatternFill(fgColor='00ff00', fill_type='solid')
sheet1['A2'].fill = PatternFill(fgColor=Color(rgb='00ff00', tint=0.3), fill_type='darkTrellis')
sheet1['A3'].fill = PatternFill(fgColor=Color(rgb='00ff00', tint=0.7), fill_type='lightHorizontal')
sheet1['A4'].fill = PatternFill(fgColor=Color(rgb='00ff00', tint=1), fill_type='solid')
sheet1['C2'].border = Border(bottom=Side(style='thin', color='00ffff'),
right=Side(style='double', color='0000ff'),
left=Side(style='hair', color='0000ff'),
top=Side(style='dashDotDot', color='0000ff'))
sheet1['C2'].value = '边框'
sheet1['D4'].alignment = Alignment(horizontal='center', vertical='center')
sheet1['D4'].value = '对齐'
wb.save(filename=dest_filename)