1. 程式人生 > >C# 在PowerPoint中插入組合形狀

C# 在PowerPoint中插入組合形狀

形狀是PowerPoint中最常見的元素,在PowerPoint中,我們可以插入多個形狀然後將形狀組合,以便它們作為一個單元來工作。本文將介紹如何使用.NET PowerPoint元件和C#在PowerPoint幻燈片中建立組合形狀。

在使用以下程式碼前,需要下載Spire.Presentation,並引用Spire.Presentation.dll到工程中。

//建立PowerPoint文件
Presentation ppt = new Presentation();

//獲取第一張幻燈片
ISlide slide= ppt.Slides[0];

//新增一個矩形
IShape rectangle = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(20, 100, 200, 40));
rectangle.Fill.FillType = FillFormatType.Solid;
rectangle.Fill.SolidColor.KnownColor = KnownColors.Gold;
rectangle.Line.Width = 0.1f;

//新增一個帶狀形狀
IShape ribbon = slide.Shapes.AppendShape(ShapeType.Ribbon2, new RectangleF(60, 75, 120, 80));
ribbon.Fill.FillType = FillFormatType.Solid;
ribbon.Fill.SolidColor.KnownColor = KnownColors.Purple;
ribbon.Line.Width = 0.1f;

//將兩個形狀新增到ArrayList陣列
ArrayList list = new ArrayList();
list.Add(rectangle);
list.Add(ribbon);

//組合陣列中的形狀
ppt.Slides[0].GroupShapes(list);

//儲存文件
ppt.SaveToFile("output.pptx", FileFormat.Pptx2010);

C# PPT 中如何組合形狀