From 5edc6e84a28f58fa76d753780dcd370e92327adc Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Mon, 12 Sep 2022 15:08:49 -0300 Subject: [PATCH 1/2] #Fix: System.ArgumentException: Can't set color when patterntype is not set. --- dotnet/src/dotnetframework/GxExcel/GxExcelEPPlus.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dotnet/src/dotnetframework/GxExcel/GxExcelEPPlus.cs b/dotnet/src/dotnetframework/GxExcel/GxExcelEPPlus.cs index 64a53a3dc..d9e57eb83 100644 --- a/dotnet/src/dotnetframework/GxExcel/GxExcelEPPlus.cs +++ b/dotnet/src/dotnetframework/GxExcel/GxExcelEPPlus.cs @@ -831,7 +831,11 @@ public int BackColor System.Drawing.Color color = System.Drawing.Color.FromArgb(red, green, blue); - pCells[i].Style.Fill.BackgroundColor.SetColor(color); + if (pCells[i].Style.Fill.PatternType == ExcelFillStyle.None) + { + pCells[i].Style.Fill.PatternType = ExcelFillStyle.Solid; + } + pCells[i].Style.Fill.BackgroundColor.SetColor(color); } } From b0a805bd829526023807d11b3971b67a32203e6c Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Thu, 15 Sep 2022 13:43:39 -0300 Subject: [PATCH 2/2] Use Color resolver for ExcelBackColor --- dotnet/src/dotnetframework/GxExcel/GxExcelEPPlus.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/dotnet/src/dotnetframework/GxExcel/GxExcelEPPlus.cs b/dotnet/src/dotnetframework/GxExcel/GxExcelEPPlus.cs index d9e57eb83..fb0c151df 100644 --- a/dotnet/src/dotnetframework/GxExcel/GxExcelEPPlus.cs +++ b/dotnet/src/dotnetframework/GxExcel/GxExcelEPPlus.cs @@ -824,20 +824,12 @@ public int BackColor for (int i = 1; i <= cntCells; i++) { - int val = (int)value; - int red = val >> 16 & 0xff; - int green = val >> 8 & 0xff; - int blue = val & 0xff; - - System.Drawing.Color color = System.Drawing.Color.FromArgb(red, green, blue); - if (pCells[i].Style.Fill.PatternType == ExcelFillStyle.None) { pCells[i].Style.Fill.PatternType = ExcelFillStyle.Solid; } - pCells[i].Style.Fill.BackgroundColor.SetColor(color); - } - + pCells[i].Style.Fill.BackgroundColor.SetColor(GXExcelHelper.ResolveColor(value)); + } } }