Setting Excel cell colors using RGB values

I am trying to set Excel cells using RGB values, not the way it is currently done, as I need to set the cells to a specific color and not a standard color.

This is how I do it now:

ChartRange.Interior.Color = Microsoft.Office.Interop.Excel.XlRgbColor.rgbRed;

      

Is it possible to set color in RGB values ​​in C #?

I am working with Excel sheets that had colors set by RGB values ​​in VBA.

+3


source to share


2 answers


You can assign System.Drawing.Color

using FromArgb

as below:



ChartRange.Interior.Color = System.Drawing.Color.FromArgb(255, 0, 0);

      

+4


source


You can convert from System.Drawing.Color

using System.Drawing.ColorTranslator

which will allow you to set RGB values.

Something like that:



System.Drawing.Color color = System.Drawing.Color.FromArgb(255, 0, 0);
ChartRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(color);

      

+2


source







All Articles