【问题标题】:Fill a specific Shape - ShapeStyle with color C# PowerPoint OpenXML填充特定形状 - 使用颜色 C# PowerPoint OpenXML 的 ShapeStyle
【发布时间】:2016-07-25 12:28:57
【问题描述】:

我想更改幻灯片中几个形状的填充颜色。

我在 msdn 上找到了这个教程,但它只提到了一个非常具体的场景(第一张幻灯片的第一个形状,在只有一个形状的演示文稿中)=> Link To The MSDN Tutorial

所以,也许我并不真正了解整个事情,但在我看来,当您尝试动态访问 ShapeTree 元素时,您会收到“nullReference 异常”或“未定义为对象的实例” ",在尝试访问 ShapeStyle 属性时(即使实际上是 FirstChild() 示例)。

所以我尝试通过遍历元素来按如下方式访问它,但都没有成功。

 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        
                }

           }

我的目标很简单,我想通过识别它的 innerText 来更改形状的填充颜色。

提前致谢!

干杯

【问题讨论】:

    标签: c# powerpoint openxml


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-05
    • 2016-01-13
    • 2014-05-26
    • 1970-01-01
    • 2014-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多