On 21 Feb 2022, at 12:58, Vadim Popko wrote:
> class Excel:
>
> def __init__(self):
>
> self.wb = xl.Workbook()
>
> del self.wb['Sheet']
>
> self.consolas = NamedStyle(name='Consolas')
>
> self.consolas.font = Font(name='Consolas', size=10)
>
> self.consolas.alignment = Alignment(horizontal='center',vertical='center')
>
Hi Vadim,
as per the bug report I think the problem is that you are essentially continually attempting to register a new named style. You should probably have a method that checks for the style in the workbook and adds it if necessary:
if "Consolas" not in wb.named_styles:
wb.add_named_style(…)
You already have some code that does some checking so it probably makes sense to the check there.
Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Sengelsweg 34
Düsseldorf
D- 40489
Tel: +49-203-3925-0390
Mobile: +49-178-782-6226
From what I’ve seen in similar OpenPyXL discussions, a lot of formatting or text-handling quirks come down to how strings are processed before writing them into cells. If you’re dealing with styled or special character text, it helps to normalize it first to avoid encoding surprises. I’ve experimented with different text styles from tools like https://stylishnamees.com/ and noticed that keeping things Unicode-friendly makes a big difference when exporting to Excel.