简体   繁体   中英

Powerpoint VSTO how to insert slide into section

I am working on a Powerpoint addin, that helps with creating agenda slides. I have to insert a slide at a specific location, which is easy using presentation.Slides.AddSlide(index, customlayout). But since I am also using sections, this always inserts the slide inside the first (default) section.

Here's an example structure. I would like to replace Page 1 at it 's current position. For this I would need to insert a slide at slideIndex=2, but as it stands now, the slide will end up below "Header Page".

  • Default Section
    • Header Page
  • Section 1
    • Page 1
    • Page 2

And here is some code I am using

private static PPT.Slide RefreshDefaultAgendaFormat(PPT.Presentation presentation, PPT.CustomLayout customAgendaLayout, PPT.Slide currentSlide)
    {
        int tempindex = currentSlide.SlideIndex;
        int tempSectionIndex = currentSlide.sectionIndex;

        currentSlide.Delete();
        currentSlide = presentation.Slides.AddSlide(tempindex, customAgendaLayout);

        return currentSlide;
    }

I managed to solve it by changing the order of operations and adding it at the current index+1.

    int tempindex = currentSlide.SlideIndex;
    int tempSectionIndex = currentSlide.sectionIndex;
    PPT.Slide newSlide = presentation.Slides.AddSlide(tempindex + 1, customAgendaLayout);
    currentSlide.Delete();
    return newSlide;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM