How to fill a specific Excel cell with color using openpyxl?

I am currently using openpyxlexcel to modify specific cells. I can easily change the font styles, just simple:

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

But I can’t change the filling of a specific cell. Does anyone know any documentation on how to do this? I want to just change the color of one cell, so what other packages are needed?

I tried to learn some other things, such as PatternFill, but I couldn’t get exactly what I was looking for. All I need to do is change the fill color in one cell.

+4
source share
1 answer

What was the PatternFill you tried to use? Is this something like this?

from openpyxl.styles import PatternFill

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

:

ws['A1'].fill = redFill

:

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

All Articles