I'm trying to fill programmatically the cells of Excel with colors using the export method I found about through this post. I've noticed the library contains a method called AddFill with the following parameters AddFill(int startRow, int startColumn, int endRow, int endColumn, string fgColor, string bgColor, [bool doNotOverride = false])
but everything I set as fgColor and/or bgColor makes the cell color go full black. I've tried "red", "Red", "RED", "#FF0000", "(255,0,0)" and its always the same result. It would be very helpful if anyone knows how to do that using the library Acumatica uses to fill the cell with color
Asked
Active
Viewed 193 times
0

DanielMoncadaZ
- 39
- 7
1 Answers
1
There is a utility method PX.Export.Excel.Core.Utils.RgbToColor
in Acumatica libraries to convert the value from a .Net Color class integer ARGB value:
AddFill(startRow, startColumn, endRow , endColumn,
PX.Export.Excel.Core.Utils.RgbToColor(System.Drawing.Color.AliceBlue.ToArgb()),
PX.Export.Excel.Core.Utils.RgbToColor(System.Drawing.Color.FromArgb(255, 0, 0).ToArgb()));
The method is public so you should be able to re-use it but in case you have to roll your own here is the implementation:
public static string RgbToColor(int rgb)
{
if (rgb == 0) return "00000000";
return rgb.ToString("x");
}
Basically the expected format can be achieved by calling the ToString
method of a integer object with parameter x
. I believe this returns an integer value in the form of an hexadecimal string.
More details about this format can be found here: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#XFormatString
Hardcoded string '00000000' is a special case with a meaning of 'no color' for Excel.

Hugues Beauséjour
- 8,067
- 1
- 9
- 22