C#设置PPT中的形状组合/取消组合
PPT中的形状通过组合的方式可以将多个形状组合为一个整体的形状,或者也可以将原有的组合形状取消组合,还原为多个单独形状。下面通过C#代码展示如何来实现形状组合和取消组合。
工具/材料
.NETFrameWork4.5.1
VisualStudio2013
Spire.Presentationfor.NET6.1
1.组合PPT中的形状
第01步、
usingSpire.Presentation;usingSpire.Presentation.Drawing;usingSystem.Collections;usingSystem.Drawing;namespaceGroupShapes{classProgram{staticvoidMain(string[]args){//创建一个PPT文档,并获取第一张幻灯片Presentationppt=newPresentation();ISlideslide=ppt.Slides[0];//添加一个圆形IAutoShapeshape1=slide.Shapes.AppendShape(ShapeType.Ellipse,newRectangleF(289,166,120,120));shape1.Fill.FillType=FillFormatType.Solid;shape1.Fill.SolidColor.Color=Color.White;shape1.Line.FillType=FillFormatType.Solid;shape1.Line.SolidFillColor.Color=Color.Purple;shape1.Name="Shape1";//添加一个五角星形状IAutoShapeshape2=slide.Shapes.AppendShape(ShapeType.FivePointedStar,newRectangleF(300,170,100,100));shape2.Fill.FillType=FillFormatType.Solid;shape2.Fill.SolidColor.Color=Color.Orange;shape2.Line.FillType=FillFormatType.None;shape2.Name="Shape2";//设置五角星形状的光边效果GlowEffectglow=newGlowEffect();glow.ColorFormat.Color=Color.Red;glow.Radius=3.0;shape2.EffectDag.GlowEffect=glow;//将shape5和shape6两个形状组合ArrayListlist=newArrayList();list.Add(shape1);list.Add(shape2);slide.GroupShapes(list);//保存文档ppt.SaveToFile("GroupShapes.pptx",FileFormat.Pptx2013);System.Diagnostics.Process.Start("GroupShapes.pptx");}}}
第02步、
形状组合效果:
2.取消PPT中的形状组合
第01步、
usingSpire.Presentation;namespaceUngroupShapes{classProgram{staticvoidMain(string[]args){//加载PPT测试文档Presentationppt=newPresentation();ppt.LoadFromFile("GroupShapes.pptx");//获取幻灯片ISlideslide=ppt.Slides[0];//获取形状IShapeshape=slide.Shapes[0];//判断是否为组合形状if(shapeisGroupShape){GroupShapegroupShape=shapeasGroupShape;//获取组合形状中的子形状slide.Ungroup(groupShape);}//保存文档ppt.SaveToFile("UngroupShapes.pptx",FileFormat.Pptx2013);System.Diagnostics.Process.Start("UngroupShapes.pptx");}}}
第02步、
完成代码编辑后,运行程序,生成文档。在结果文档中,可查看形状取消组合效果。
上一篇:怎么把桌面共享给别人
下一篇:iphone如何关闭轻点唤醒