from openpyxl import Workbookfrom openpyxl.styles import Color, PatternFill, Fontfrom openpyxl.styles.fills import FILL_SOLIDfrom openpyxl.styles.colors import BLACKfrom openpyxl.utils import get_column_letterwb = Workbook()ws = wb.activec = ws['A1']fill = PatternFill(patternType=FILL_SOLID, fgColor=(rgb="0000FF")) # 这里使用的是 RGB格式font = Font(color="FFBB00") # 这里使用RGB格式ws.sheet_properties.tabColor = BLACK# 填充一个单元格c.value = "this is new value"c.font = fontc.fill = fill# 填充一行cells = ws.row_dimensions[1]row.font = fontrow.fill = fill# 填充指定长度的行start_chr = "A"end_chr = get_column_letter(5) # 这个方法可以解决AA列名问题fill_cells = ws["%s1" % start_chr : "%s1" % end_chr]for tmp_c in fill_cells[0]: tmp_c.font = font tmp_c.fill = fontwb.save(filename='test.xlsx')