From 9fc7d193b3f28e500788290b31927cbabe2e6ed5 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Wed, 1 May 2024 09:10:53 -0600 Subject: [PATCH] Fix xfId included in CellStyleXfs XML --- OpenXmlFormats/Spreadsheet/Styles/CT_CellStyleXfs.cs | 2 +- OpenXmlFormats/Spreadsheet/Styles/CT_Xf.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/OpenXmlFormats/Spreadsheet/Styles/CT_CellStyleXfs.cs b/OpenXmlFormats/Spreadsheet/Styles/CT_CellStyleXfs.cs index 6f851840a..5338b84c2 100644 --- a/OpenXmlFormats/Spreadsheet/Styles/CT_CellStyleXfs.cs +++ b/OpenXmlFormats/Spreadsheet/Styles/CT_CellStyleXfs.cs @@ -44,7 +44,7 @@ internal void Write(StreamWriter sw, string nodeName) { foreach (CT_Xf x in this.xf) { - x.Write(sw, "xf"); + x.Write(sw, "xf", true); } } sw.Write(string.Format("", nodeName)); diff --git a/OpenXmlFormats/Spreadsheet/Styles/CT_Xf.cs b/OpenXmlFormats/Spreadsheet/Styles/CT_Xf.cs index 621251dd7..3ae3e75cf 100644 --- a/OpenXmlFormats/Spreadsheet/Styles/CT_Xf.cs +++ b/OpenXmlFormats/Spreadsheet/Styles/CT_Xf.cs @@ -109,14 +109,15 @@ public static CT_Xf Parse(XmlNode node, XmlNamespaceManager namespaceManager) - internal void Write(StreamWriter sw, string nodeName) + internal void Write(StreamWriter sw, string nodeName, bool writingCellStyle=false) { sw.Write(string.Format("<{0}", nodeName)); XmlHelper.WriteAttribute(sw, "numFmtId", this.numFmtId, true); XmlHelper.WriteAttribute(sw, "fontId", this.fontId, true); XmlHelper.WriteAttribute(sw, "fillId", this.fillId, true); XmlHelper.WriteAttribute(sw, "borderId", this.borderId, true); - XmlHelper.WriteAttribute(sw, "xfId", this.xfId, true); + if (!writingCellStyle) + XmlHelper.WriteAttribute(sw, "xfId", this.xfId, true); XmlHelper.WriteAttribute(sw, "quotePrefix", this.quotePrefix,false); XmlHelper.WriteAttribute(sw, "pivotButton", this.pivotButton, false); if(this.applyNumberFormat)