Skip to content
Advertisement

Fill cells with colors using openpyxl?

I am currently using openpyxl v2.2.2 for Python 2.7 and i wanted to set colors to cells. I have used the following imports

JavaScript

and the following is the code I tried using:

JavaScript

but I get the following error:

JavaScript

Any idea on how to set cell A1 (or any other cells) with colors using openpyxl?

Advertisement

Answer

I believe the issue is that you’re trying to assign a fill object to a style.

ws['A1'].fill = redFill should work fine.

Advertisement