from openpyxl.styles import Font, PatternFill, Border, Side, Alignment, Protection from openpyxl.styles import numbers wb = Workbook() ws = wb.active ws.cell(row=1, column=1, value='宋体').font = Font(name=u'宋体', size=12, bold=True, color='FF0000') ws.cell(row=2, column=2, value='右对齐').alignment = Alignment(horizontal='right') ws.cell(row=3, column=3, value='填充渐变色').fill = PatternFill(fill_type='solid', start_color='FF0000') ws.cell(row=4, column=4, value='设置边线').border = Border(left=Side(border_style='thin', color='FF0000'), right= Side(border_style='thin', color='FF0000')) ws.cell(row=5, column=5, value='受保护的').protection = Protection(locked=True, hidden=True) ws.cell(row=6, column=6, value=0.54).number_format =numbers.FORMAT_PERCENTAGE
单元格格式设置
标签:openpyxl,column,value,cell,color,ws,基本操作,row
From: https://www.cnblogs.com/chiemn/p/17756722.html