Add Slides
To add a slide to a presentation, use the PPT API to add slide based on a slide layout defined in the PowerPoint® presentation template. If the template does not include slide layout that meets your requirements, you can add a slide layout. For details, see Add a Slide Layout.
To add a slide, use the add
method with an
mlreportgen.ppt.Presentation
object. For example, using the
default PPT API template, you can add a slide using the Title and Content slide
layout.
import mlreportgen.ppt.*; ppt = Presentation('myPresentation'); slide1 = add(ppt,'Title and Content');
When you add a slide, the PPT API creates an mlreportgen.ppt.Slide
object. However, you cannot add a slide by using a Slide
constructor.
Specify the Order of a Slide
By default, the order in which you add slides in a PPT API program determines the
order in which the slides appear. For example, this code makes the
titleSlide
slide the first slide in the presentation. The
contentSlide
slide is the second slide.
ppt = Presentation('myPresentation'); titleSlide = add(ppt,'Title Slide'); contentSlide = add(ppt,'Title and Content');
When you add a slide, to specify explicitly the order in which it appears, you can:
Specify the slide the new slide precedes. This approach is useful to keep slides together as you add or delete slides.
Specify an index indicating the numerical position of the slide in the presentation. This approach is useful when you want a slide to appear always in the same numerical position.
The first approach places the new slide immediately before slide you specify. If
you created the reference slide using the PPT API, you can specify the
Slide
object. For example, using the default PPT API
template, this code causes the pictureSlide
to appear immediately
before the introSlide
.
ppt = Presentation('myPresentation'); titleSlide = add(ppt,'Title Slide'); introSlide = add(ppt,'Title Slide'); pictureSlide = add(ppt,'Title and Picture',introSlide);
In a presentation created using PowerPoint, adding a slide immediately before a slide that you created using PowerPoint requires a few steps.
In PowerPoint, identify the position of the reference slide you want the new slide to precede.
Open the PPT API program and give a name to the reference slide you want to position the new slide before. For example, assume that the reference slide is the second slide in a PowerPoint presentation.
ppt = Presentation('myPresentation','myPresentation'); open(ppt); ppt.Children(2).Name = 'ReferenceSlide'; close(ppt);
To identify the reference slide object, use the slide name. Add the new slide relative to the reference slide.
ppt = Presentation('myPresentation', 'myPresentation'); open(ppt); refSlide = find(ppt, 'ReferenceSlide'); add(ppt, 'Blank', refSlide); close(ppt);
To use the second approach, specify an index representing the numerical position
for the slide. For example, using the default PPT API template, this code makes
pictureSlide
the second slide in the presentation.
ppt = Presentation('myPresentation'); titleSlide = add(ppt,'Title Slide'); introSlide = add(ppt,'Title and Content'); pictureSlide = add(ppt,'Title and Picture',2);
Specify the Slide Master
A template can have multiple slide masters. Two or
more slide masters can have a child slide layout with
the same name. By default, when you specify the slide layout using PPT API, the API
uses the first slide layout that has the name you specify. If you specify a slide
master in an add
method, specify the
slide master argument immediately after the slide
layout argument. For example, this code uses the Title Slide
slide layout that is a child of the
myCustomMaster
slide
master.
ppt = Presentation('myPresentation'); titleSlide = add(ppt,'Title Slide',myCustomMaster);