Cell styles that have multiple font colours are not preserved

Issue #340 resolved
stringfellow created an issue

See attached sheet. Cell A1 contains a text item that has multiple styles applied across it.

OpenPyXL does not preserve these styles.

Comments (6)

  1. CharlieC

    There is no reliable API for multiple styles within a cell. It relies on the sharedStrings.xml which is officially optional.

  2. stringfellow reporter

    Ah ok. What do you mean by 'officially optional'? Sorry, I'm not very familiar with the standard.

  3. CharlieC

    See section 18.4 of the specification.

    "The goal of implementing a single string table that is shared across the workbook is to improve performance in opening and saving the file by only reading and writing the repetitive information once."

    There are problems with this - not least there is no enforcement for unique values - using the same object for sub-cell formatting makes an additional mockery of the whole thing. You can see this if you look at the source of your file.

    We're currently considering dropping its use entirely as it can be quite a bottleneck.

  4. stringfellow reporter

    I understand the burden! Thanks!

    Is this basically because Excel just does things its own way?

  5. CharlieC

    Sort of. In certain places the specification looks rushed and not very well thought through and sometimes this is probably just to do just enough to replicate current behaviour. It's one of the reasons why it's so difficult why so few programs or libraries pretend to provide 100% functionality. It would be possible to read and write such information by essentially embedding the formatting information in the string but I'm not sure how that would be modelled in Python, ie. what you'd get when looking at the value of such a cell. And providing that kind of support would also place a large burden of knowledge with client code: if we were to preserve it you'd have to parse both the formatting information and value yourself.

  6. Log in to comment