Quantcast
Channel: Open XML Format SDK forum
Viewing all articles
Browse latest Browse all 1288

Fill a specific Shape - ShapeStyle with color C# PowerPoint OpenXML

$
0
0

I would like to change the fill color of a few shapes in a slide.

I found this tutorial on msdn, but it only mention a very specific scenario (first shape of first slide, in a presentation where there is only one shape) => Link to the MSDN tutorial

It seems  that when Itry to access the ShapeTree Elements dynamically, Iget a "nullReference exception" or a "not define as an instance of an object", when trying to access the ShapeStyle property (even with the FirstChild() example actually).

So I tried to access it as follows, by itering through the Elements, but no success neither.

ShapeTree tree = slide.Slide.CommonSlideData.ShapeTree;
            for (var i = 0; i <= 30; i++)
            {
                try
                {
                    DRAW.FillReference fillRef = tree.ElementAt(i).GetFirstChild<DocumentFormat.OpenXml.Presentation.Shape>().ShapeStyle.FillReference;


                    fillRef.SchemeColor = new DRAW.SchemeColor();
                    fillRef.SchemeColor.Val = DRAW.SchemeColorValues.Accent6;

                }
                catch (Exception e)
                {
                //Null reference Excpetion on the fillRef initialization, does the same if I cast with DocumentFormat.OpenXml.Drawing.Shape
                }

           }

My goal is really simple, I'd like to change the fill color of a shape, by identifying it's innerText.

Thanks in advance !


Viewing all articles
Browse latest Browse all 1288