question

PedroCruz-9816 avatar image
0 Votes"
PedroCruz-9816 asked PedroCruz-9816 commented

c# Excel Interop known Color as RGB does not display right in shape in sheet

Hello,

I'm trying to create a textbox and fill it with a specific colour.
So far, I managed to do it but the result seems not to match with the colour that I specify.
This is an example:


Color colour = Color.Red; // -> define my colour
Excel.Shape textbox = worksheet.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, (float)x3, (float)y3, 100, 100);
var infoToDisplay = "#####";
textbox.TextFrame.Characters(System.Type.Missing, System.Type.Missing).Text = infoToDisplay;
textbox.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = Color.White.ToArgb(); //-> text in white
textbox.Fill.ForeColor.RGB = colour.ToArgb(); // -> fill colour using a known Color

The result is a Blue fill not Red as I am specifying.
This is the same for different types of shapes e.g. line.

What is happening?
This may be a simple correction but I'm not sure why it happens.
Can anyone support, please?

Thank you.

Regards,
Pedro


dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered PedroCruz-9816 commented

Use

  textbox.Fill.ForeColor.RGB =  ColorTranslator.ToWin32(colour);
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you. Works perfectly.

0 Votes 0 ·