Accessing section

Hi There,

I was looking at using sections in my “Template” PPTX to allow a little more flexibility to clone multiple slides that are related. I have not been able to find a way to get a section of a powerpoint in Gembox. Is this a thing that can be done?

Any help would be greatly appreciated.
Cheers,
Nathan

Hi,

GemBox.Presentation currently doesn’t provide API support for sections.
However, we have decided that we will implement this feature for you.
I will contact you again soon.

Regards,
Mario

Thanks Mario,

That is greatly appreciated!

Looking forward to hearing from you.
Cheers,
Nathan

Hi Mario,

Just wondering what sort of timeframe until we see this implemented and available for us to code against?
Kind regards,
Nathan

Hi Nathan,

Please try again with this bugfix:
https://www.gemboxsoftware.com/presentation/nightlybuilds/GBP25v1136.zip

Or this NuGet package:
Install-Package GemBox.Presentation -Version 25.0.1136-hotfix

We added support for PresentationDocument.Sections collection. For your use case, you can use something like the following to iterate through slides of some specific section:

PresentationDocument presentation = PresentationDocument.Load("Template.pptx");
Section section = presentation.Sections.First(s => s.Name == "My Section");
foreach (Slide slide in section.Slides)
{
    // TODO...
}

I hope this helps.

Regards,
Mario

Is there any way to put a slide into a section?

i.E. Pseudecode:
presentation.Sections[0].Slides.Add/Insert( ...
or Pseudecode:
slide.Section = "Some Section";

Thanks, Lars

Hi Lars,

The Section can define the first slide with which it begins (Section.FirstSlide), and it ends before the first slide of the next section (or the end of the presentation).

So, to put the slide into a section, you need to move it between the first slide of the section that you’re targeting and the first slide of the next section.

For example, try the following:

var presentation = new PresentationDocument();

for (int i = 0; i < 10; i++)
    presentation.Slides.AddNew(SlideLayoutType.Custom)
        .Content.AddShape(ShapeGeometryType.RoundedRectangle, 100, 100, 100, 100)
        .Text.AddParagraph().AddRun("Slide " + i);

presentation.Sections.AddNew("Section 0-2", presentation.Slides[0]);
presentation.Sections.AddNew("Section 3-5", presentation.Slides[3]);
presentation.Sections.AddNew("Section 6-9", presentation.Slides[6]);

// Move "Slide 8" before "Slide 1", as a result, the slide is moved from "Section 6-9" to "Section 0-2".
var slide8 = presentation.Slides[8];
presentation.Slides.Remove(slide8);
presentation.Slides.Insert(1, slide8);

presentation.Save("output.pptx");

Does this solve your issue?

Regards,
Mario

Hi Mario,
that will do the trick.
Thank you!
Lars