From fd4b381981e4b9a6e17242cb16faf516fcc06e13 Mon Sep 17 00:00:00 2001 From: Artem Koloskov Date: Thu, 15 Sep 2022 12:16:47 +0700 Subject: [PATCH] Upstream-fix: Add AddColor method to CT_Font XSSFFontFormatting.FontColor setter used to set a new color to the CT_Font/colorField list which was not always initialised. Thsi adds a method which first will check if the list is initialized and then adds a color to it. XSSFFontFormatting.FontColor setter now uses this method to set a color. --- OpenXmlFormats/Spreadsheet/Styles/CT_Font.cs | 8 ++++++++ ooxml/XSSF/UserModel/XSSFFontFormatting.cs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/OpenXmlFormats/Spreadsheet/Styles/CT_Font.cs b/OpenXmlFormats/Spreadsheet/Styles/CT_Font.cs index 98011b82e..96c21692b 100644 --- a/OpenXmlFormats/Spreadsheet/Styles/CT_Font.cs +++ b/OpenXmlFormats/Spreadsheet/Styles/CT_Font.cs @@ -512,6 +512,14 @@ public CT_Color AddNewColor() this.colorField.Add(newColor); return newColor; } + public int AddColor(CT_Color value) + { + colorField = colorField ?? new List(); + + colorField.Add(value); + + return this.colorField.Count - 1; + } #endregion color #region sz diff --git a/ooxml/XSSF/UserModel/XSSFFontFormatting.cs b/ooxml/XSSF/UserModel/XSSFFontFormatting.cs index f7ff5a2d9..74b81dff3 100644 --- a/ooxml/XSSF/UserModel/XSSFFontFormatting.cs +++ b/ooxml/XSSF/UserModel/XSSFFontFormatting.cs @@ -108,7 +108,7 @@ public IColor FontColor } else { - _font.SetColorArray(0, xcolor.GetCTColor()); + _font.AddColor(xcolor.GetCTColor()); } } }