3
votes

I use Microsoft.Office.Interop.PowerPoint to generate powerpoint files from a C# application.
I'm on Office 2007 SP2.

I generate charts, and I want to defines the colors of my series with something like this:

serie.Border.Color = Color.Red.ToArgb(); 

and I do this with different colors.

My problem is that when the slides are generated, the colors are not the same : when I define a serie in Red, it is drawn in Blue, and the Blue is rendered in Red. (The green stays green).

Isn't the ToArgb() the method to use when I want to send a color to powerpoint?
Do I have to use an other method from the Color type, or is there a manual conversion to do?

2

2 Answers

3
votes

I came across the same problem a few years ago. It really is strange and I couldn't find any documentation about it, but basically, red and blue are mixed.

Back then, I wrote these methods:

public static int ToBgr(this Color color)
{
    return ToBgr(color.R, color.G, color.B);
}

public static int ToBgr(int r, int g, int b)
{
    //  & 0xFFFFFF -> Strip away alpha channel which powerpoint doesn't like
    return Color.FromArgb(b, g, r).ToArgb() & 0xFFFFFF;
}

Use it like this:

serie.Border.Color = Color.Red.ToBgr(); 
0
votes

I ran into the same issue and figured out a working solution. I have posted the answer in this link, that might be helpful if anyone is still having trouble.

https://stackoverflow.com/a/18794046/2752556