[英]reformat dataframe using openpyxl
I have a unformatted dataframe, that I would like to re-format using Openpyxl.我有一个未格式化的数据框,我想使用 Openpyxl 重新格式化。
Data数据
id consumed_q122 available_q122 consumed_q122 available_q222
aa 727.2 272.8 975.7 24.3
bb 0 1000 117.3 882.7
Desired期望的
Doing正在做
from openpyxl.styles import colors
from openpyxl.styles import Font, Color
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
from openpyxl.styles import PatternFill
sheet['A1'].fill = PatternFill(bgColor="808080", fill_type = "solid") #grey
sheet['B1'].fill = PatternFill(bgColor="FFC0CB", fill_type = "solid") #pink
sheet['C1'].fill = PatternFill(bgColor="FFC0CB", fill_type = "solid") #pink
sheet['D1'].fill = PatternFill(bgColor="add8e6", fill_type = "solid") #blue
sheet['E1'].fill = PatternFill(bgColor="add8e6", fill_type = "solid") #blue
I am researching how to:
1. make the header fonts bold and black
2. make the headers 'wrap text'
Any suggestion is appreciated.任何建议表示赞赏。
Sorry I fail to laod your desired image.对不起,我没能找到你想要的形象。 Refer to what you are working on:
请参阅您正在处理的内容:
headers fonts bold and black can be set by font标题字体粗体和黑色可以通过字体设置
headers 'wrap text' can be set by alignment headers 'wrap text' 可以通过对齐方式设置
from openpyxl.styles import Alignment, Font font1 = Font(color=colors.BLACK,b=True) algn1 = Alignment(wrapText=True) sh.cell(row=1,column=1).font = font1 sh.cell(row=1,column=2).alignment = algn1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.