I'm trying to set Excel cells using RGB values rather than the way I do it currently as i need to set cells to a specific colour rather than a set standard colour.
This is how i currently do it:
ChartRange.Interior.Color = Microsoft.Office.Interop.Excel.XlRgbColor.rgbRed;
Is it possible to set colour in RGB values in C#?
I am working with Excel sheets that have had the colours set by RGB values in VBA.
On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Color Scales. Select a two-color scale. Hover over the color scale icons to see which icon is a two-color scale. The top color represents higher values, and the bottom color represents lower values.
Go to Home >> Styles >> Conditional Formatting >> Highlight Cells Rules >> Equal To. In Equal To dialog box put the number and assign the color that you want to it, then click OK. Do the same steps for each number.
You can able to assign the System.Drawing.Color
using FromArgb
as below:
ChartRange.Interior.Color = System.Drawing.Color.FromArgb(255, 0, 0);
You can convert from a System.Drawing.Color
using System.Drawing.ColorTranslator
which will let you set using RGB values.
Something like this:
System.Drawing.Color color = System.Drawing.Color.FromArgb(255, 0, 0);
ChartRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(color);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With