discover
discover

Reputation: 559

Way to remove custom style with openpyxl

I can add custom style using NamedStyle from openpyxl. Is there any way to get existing custom styles and remove using openpyxl?

Upvotes: 3

Views: 1742

Answers (2)

rabkaman
rabkaman

Reputation: 131

I ran into this issue as well so I hacked until this worked. I used the _named_styles , which isn't exactly best practice, but it gets the job done.

I used list comp returning index from an index value lookup

del wb._named_styles[ wb.style_names.index('yourstyle')]

I put this additional check to make certain its present before deleting

if a_style in wb.named_styles:
        del wb._named_styles[ wb.style_names.index(a_style)]

Upvotes: 2

Achide
Achide

Reputation: 1

Hi it seems like you can use workbook.named_styles to get style list. This will return a list including all style exist.

Upvotes: 0

Related Questions