Skip to content
Advertisement

Style Normal exists already – Python – OpenPyxl

I have looked into many stackoverflow questions but none of them seemed to solve my problem. I am using Python and Openpyxl to fill a whole row with red given a certain condition. I did all the importations necessary :

JavaScript

And my code is the following :

JavaScript

When I ask to print the first occurence of cell it gives me

JavaScript

which is what I am looking for. However, the following error comes every time : “Style Normal exists already”. There is absolutely no cell formatting or style whatsoever in the rest of the code but the Excel file cells are indeed filled with yellow already.

Any idea on how to solve this ? Thanks in advance for any help.

Advertisement

Answer

If using a NamedStyle, you’re required to pass a name.

JavaScript

Since you’re assigning this NamedStyle to more than one cell, it makes sense to register it to your workbook.

JavaScript

Then you can update it’s application to cells, like so:

JavaScript

Reference:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement