C# 设置PPT中的形状组合/取消组合

PPT中的形状通过组合的方式可以将多个形状组合为一个整体的形状 , 或者也可以将原有的组合形状取消组合 , 还原为多个单独形状 。 下面通过C#代码展示如何来实现形状组合和取消组合 。 1. 组合PPT中的外形01 using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Collections;
using System.Drawing;

namespace GroupShapes
{
class Program
{
static void Main(string[] args)
{
//建立一个PPT文档 , 并获取第一张幻灯片
Presentation ppt = new Presentation();
ISlide slide = ppt.Slides[0];

//添加一个圆形
IAutoShape shape1 = slide.Shapes.AppShape(ShapeType.Ellipse, new RectangleF(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";

//添加一个五角星外形
IAutoShape shape2 = slide.Shapes.AppShape(ShapeType.FivePointedStar, new RectangleF(300, 170, 100, 100));
shape2.Fill.FillType = FillFormatType.Solid;
shape2.Fill.SolidColor.Color = Color.Orange;
shape2.Line.FillType = FillFormatType.None;
shape2.Name = "Shape2";

//设置五角星外形的光边结果
GlowEffect glow = new GlowEffect();
glow.ColorFormat.Color = Color.Red;
glow.Radius = 3.0;
shape2.EffectDag.GlowEffect = glow;

//将shape5和shape6两个外形组合
ArrayList list = new ArrayList();
list.Add(shape1);
list.Add(shape2);
slide.GroupShapes(list);

//保留文档
ppt.SaveToFile("GroupShapes.pptx", FileFormat.Pptx2013);
System.Diagnostics.Process.Start("GroupShapes.pptx");
}
}
}

02 【C# 设置PPT中的形状组合/取消组合】外形组合结果:

C# 设置PPT中的形状组合/取消组合

文章插图




2. 打消PPT中的外形组合01 using Spire.Presentation;

namespace UngroupShapes
{
class Program
{
static void Main(string[] args)
{
//加载PPT测试文档
Presentation ppt = new Presentation();
ppt.LoadFromFile("GroupShapes.pptx");

//获取幻灯片
ISlide slide = ppt.Slides[0];

//获取外形
IShape shape = slide.Shapes[0];
//判定是否为组合外形
if (shape is GroupShape)
{
GroupShape groupShape = shape as GroupShape;
//获取组合外形中的子外形
slide.Ungroup(groupShape);
}

//保留文档
ppt.SaveToFile("UngroupShapes.pptx", FileFormat.Pptx2013);
System.Diagnostics.Process.Start("UngroupShapes.pptx");
}
}
}

02 完当作代码编纂后 , 运行程序 , 生当作文档 。 在成果文档中 , 可查看外形打消组合结果 。

C# 设置PPT中的形状组合/取消组合

文章插图



以上内容就是C# 设置PPT中的形状组合/取消组合的内容啦 , 希望对你有所帮助哦!

    推荐阅读