nissl-lab / npoi

a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
Apache License 2.0
5.67k stars 1.42k forks source link

Do not include xfId in CellStyleXfs XML #1325

Closed jones-gareth closed 4 months ago

jones-gareth commented 4 months ago

This fix removes the xfId attribute from xf elements in the cellStyleXfs collection.

When writing the styles.xml file NPOI includes a xfId attribute in the xf elements of the cell style format collection

<cellStyleXfs count="1">
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>
</cellStyleXfs>

The xfId attribute is meaningless in cellStyleXfs collections. The xf record is also used in the cellXfs collection where xfId is an index into cellStyleXfs.

If you load a generated file into Excel and save it the xfId is stripped out of cellStyleXfs elements.

Unfortunately, inclusion of the xfId attribute in the cellStyleXfs collection can cause other applications to fail. Spotfire will not read a file created with NPOI. Spotfire uses Syncfusion.XlsIO.Implementation.XmlReaders.Excel2007Parse which will crash if an xfId is present on xf records in a cellStyleXfs colllection. Spotfire will read files once the fix in this PR is applied.

tonyqus commented 4 months ago

LGTM