将颜色应用于openpyxl中的单元格

Applying colors to cell in openpyxl

我正在尝试根据 openpyxl 中单元格的值在单元格中应用背景颜色,但出现错误,有人可以提供一些工作示例吗? 我也尝试应用样式

 from openpyxl.styles import colors,Style
 mystyle=Style()
 mystyle.fill.bgColor = colors.DARKBLUE
 cell.style=mystyle

Warning (from warnings module): File "C:\Program Files\Python35\lib\site-packages\openpyxl\styles\styleable.py", line 189 warn("Use formatting objects such as font directly") UserWarning: Use formatting objects such as font directly

我会这样解决:

def colors():
    colors.gray = PatternFill(start_color='aabbcc',
               end_color='aabbcc',
               fill_type='solid')

if cell(row=x, column=y).value == 'your value':
    cell(row=i, column=14).fill = colors.gray