本文将介绍如何使用Spire.Presentation for .NET取消PowerPoint文档中的形状组合。
原PowerPoint文档含有2个形状组合:
C#
using Spire.Presentation;
namespace UngroupShapes
{
class Program
{
static void Main(string[] args)
{
//创建Presentation实例
Presentation ppt = new Presentation();
//加载PowerPoint文档
ppt.LoadFromFile("Sample.pptx");
//获取第一张幻灯片
ISlide slide = ppt.Slides[0];
//遍历幻灯片中的形状
for(int i = 0; i< slide.Shapes.Count;i++)
{
IShape shape = slide.Shapes[i];
//判断形状是否是组合形状
if (shape is GroupShape)
{
GroupShape groupShape = shape as GroupShape;
//取消形状组合
slide.Ungroup(groupShape);
}
}
//保存结果文档
ppt.SaveToFile("UngroupShapes.pptx", FileFormat.Pptx2013);
}
}
}
VB.NET
Imports Spire.Presentation
Namespace UngroupShapes
Class Program
Private Shared Sub Main(ByVal args As String())
Dim ppt As Presentation = New Presentation()
ppt.LoadFromFile("Sample.pptx")
Dim slide As ISlide = ppt.Slides(0)
For i As Integer = 0 To slide.Shapes.Count - 1
Dim shape As IShape = slide.Shapes(i)
If TypeOf shape Is GroupShape Then
Dim groupShape As GroupShape = TryCast(shape, GroupShape)
slide.Ungroup(groupShape)
End If
Next
ppt.SaveToFile("UngroupShapes.pptx", FileFormat.Pptx2013)
End Sub
End Class
End Namespace
取消形状组合后的结果文档: