From 6d40fcbf6e57397d276f23ea08a39998aace2ef5 Mon Sep 17 00:00:00 2001 From: Brandon Billingham Date: Wed, 6 Aug 2025 20:07:20 +0100 Subject: [PATCH] Fix SortCondition XML to match spec rules --- OpenXmlFormats/Spreadsheet/AutoFilter.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/OpenXmlFormats/Spreadsheet/AutoFilter.cs b/OpenXmlFormats/Spreadsheet/AutoFilter.cs index 3b0612a45..d46379afa 100644 --- a/OpenXmlFormats/Spreadsheet/AutoFilter.cs +++ b/OpenXmlFormats/Spreadsheet/AutoFilter.cs @@ -1333,9 +1333,15 @@ internal void Write(StreamWriter sw, string nodeName) XmlHelper.WriteAttribute(sw, "sortBy", this.sortBy.ToString()); XmlHelper.WriteAttribute(sw, "ref", this.@ref); XmlHelper.WriteAttribute(sw, "customList", this.customList); - XmlHelper.WriteAttribute(sw, "dxfId", this.dxfId); - XmlHelper.WriteAttribute(sw, "iconSet", this.iconSet.AsString(EnumFormat.Description)); - XmlHelper.WriteAttribute(sw, "iconId", this.iconId); + + if (this.sortBy is ST_SortBy.cellColor or ST_SortBy.fontColor) + XmlHelper.WriteAttribute(sw, "dxfId", this.dxfId); + + if (this.sortBy == ST_SortBy.icon) + { + XmlHelper.WriteAttribute(sw, "iconSet", this.iconSet.AsString(EnumFormat.Description)); + XmlHelper.WriteAttribute(sw, "iconId", this.iconId); + } sw.Write("/>"); }