writer=pd.ExcelWriter(filepath+f'05教师固定学生占比1月{today}.xlsx',engine='openpyxl')
df.to_excel(writer,sheet_name='明细')
piv1.to_excel(writer,sheet_name='1月分布')
ws=writer.book.create_sheet('口径')
ws.cell(1,1).value='综合占比:'
ws.cell(1,2).value='固定学生占比+固定学生数*0.01;'
ws.cell(2,1).value='业务解释:'
ws.cell(2,2).value='每多一个固定学生数,固定学生占比额外加1个百分点;'
from openpyxl.styles import PatternFill,Font
color='FFFF00'
ws['A1'].fill=PatternFill(start_color=color, end_color=color, fill_type="solid") #单个单元格标记黄底色
ws['A2'].fill=PatternFill(start_color=color, end_color=color, fill_type="solid") #单个单元格标记黄底色
ws['B1'].font=Font(name='Arial',size=12,bold=True,color='e64231') #单个单元格标记字体颜色
ws['B2'].font=Font(name='Arial',size=12,bold=True,color='e64231') #单个单元格标记字体颜色
writer._save()
- 背景色填充用fill
- 字体颜色调整用font
以上示例结果展示: