Ungroup Shapes in PowerPoint in C#, VB.NET

2020-09-27 07:14:50 Written by  support iceblue
Rate this item
(0 votes)

This article demonstrates how to ungroup grouped shapes in a PowerPoint document using Spire.Presentation for .NET.

The input PowerPoint document:

Ungroup Shapes in PowerPoint in C#, VB.NET

C#
using Spire.Presentation;

namespace UngroupShapes
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation ppt = new Presentation();
            //Load the PowerPoint document
            ppt.LoadFromFile("Sample.pptx");

            //Get the first slide
            ISlide slide = ppt.Slides[0];

            //Loop through the shapes in the slide
            for(int i = 0; i< slide.Shapes.Count;i++)
            {
                IShape shape = slide.Shapes[i];
                //Detect if the shape is a grouped shape
                if (shape is GroupShape)
                {
                    GroupShape groupShape = shape as GroupShape;
                    //Ungroup the grouped shape
                    slide.Ungroup(groupShape);
                }
            }

            //Save the resultant document
            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

The output PowerPoint document after ungrouping shapes:

Ungroup Shapes in PowerPoint in C#, VB.NET

Additional Info

  • tutorial_title:
Last modified on Friday, 24 September 2021 09:20