Cell style name remains same even after NamedStyle assigned to cell

Issue #682 resolved
Artem Sovetnikov
created an issue

This code produces "Normal Normal Normal" (three times Normal).

Expected result is "Normal style1 style1"

empty.xlsx is empty spreadsheet from Excel.

from openpyxl import load_workbook
from openpyxl.styles import NamedStyle

wb = load_workbook('q:\\temp\\empty.xlsx')
cell = wb.worksheets[0].cell(row=1,column=1)

ns = NamedStyle(name='style1')
cell.style = ns

cell.style = ns.name

Seems named style xfId is lost when StyleArray copy made in last line of NamedStyleDescriptor.set

This behavior prevents style copy from cell to cell just by source cell style name.

Comments (9)

  1. Steven Vereecken

    Ran in to - I think - the same issue, and had a quick (or not so quick) look... The descriptor doesn't seem to be the real problem. It seems that any NamedStyle object's as_tuple() method always returns a StyleArray with xfId 0, being the xfId of the "Normal" style. In other words: the underlying _style of the NamedStyle never gets its xfId set to that of the NamedStyle (should probably happen in _recalculate() or bind()?)

  2. Charlie Clark

    I can't rule out that the NamedStyle stuff isn't quite right. I wanted to release 2.4 and was pleasantly surprised to see people like Artem getting so much use out of it. But I won't have much time over the next few weeks to look at this in any detail. Maybe at next month's sprint. Otherwise a PR will relevant test cases would be most welcome. The existing ones maybe naive or even downright stupid but at least they define current behaviour!

  3. Log in to comment