File populated by xlsx-populate can not open with Excel
See original GitHub issueI have a template xlsm file and I use this library to populate some data. However, my template file cannot open with Excel after xlsx-populate edited. Excel prompts:
After clicking “Yes”, all cell format are lost, and Excel prompts “Removed Part: /xl/styles.xml part with XML error. (Styles) Load error. Line 1, column 0.”
According to my resarch, this is due to wrong handing for paticular cell style by xlsx-populate. When setting a cell style to horizontal center, xlsx-populate will append <alignment horizontal="center"/> after original cell style <protection locked="0"/>, look like this:
<xf numFmtId="0" fontId="8" fillId="5" borderId="1" xfId="0" applyFill="1" applyProtection="1" applyFont="1" applyBorder="1">
<protection locked="0"/>
<alignment horizontal="center"/>
</xf>
But unfortunately, it seems Excel expects all cell format property are located before <protection locked="0"/>.
If switch their positions like this:
<xf numFmtId="0" fontId="8" fillId="5" borderId="1" xfId="0" applyFill="1" applyProtection="1" applyFont="1" applyBorder="1">
<alignment horizontal="center"/>
<protection locked="0"/>
</xf>
Excel can open this file normally then.
Thank you for your contribution, your work has helped me a lot, also hope that this library can be made better.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:14 (3 by maintainers)

Top Related StackOverflow Question
-> Bump here <- I ran into this issue as well, I will attempt to debug and maybe suggest a change myself tomorrow, however I’ve only just started working with xlsx-populate ( my favorite open source repo 😉)
Actually, I’ve found it was a combination of issues. I managed to work around this one but found another issue. It only impacts excel and not open office.