How do I color-fill in a specific Excel cell using openpyxl?

9.6k Views Asked by At

I'm currently using openpyxl to modify specific excel cells. I am able to modify font styles very easily, simply just:

ws['A1'].font = Font(color=colors.White)

But I am unable to change the fill of the specific cell. Anyone know any documentation about how to do this? I want to just change the color of one cell, so what other packages are required?

I tried exploring some other things like PatternFill, but I haven't been able to accurately get what I'm looking for. All I need is to change the fill color of a single cell.

1

There are 1 best solutions below

2
On

What was the PatternFill code that you tried using? Is it something similar to this?

from openpyxl.styles import PatternFill

redFill = PatternFill(start_color='FFEE1111', end_color='FFEE1111', fill_type='solid')

Then to apply to a specific cell use:

ws['A1'].fill = redFill

Or for grading:

fill = PatternFill(fill_type=None, start_color='FFFFFFFF', end_color='FF000000')