【发布时间】: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