Main Content

replace

Class: mlreportgen.ppt.PicturePlaceholder
Namespace: mlreportgen.ppt

Replace picture placeholder with picture

Description

example

replacementPictureObj = replace(picturePlaceholder,picture) replaces the specified picture placeholder with the specified picture and returns the picture object.

Examples

expand all

Add a Title and Picture slide to a presentation and then replace the title and picture placeholders with your own title and picture.

Import the PPT namespace so that you do not have to use long, fully qualified names for the PPT API classes.

import mlreportgen.ppt.*

Create a presentation.

ppt = Presentation("myPicturePlaceholderPresentation.pptx");
open(ppt);

Add a slide that has a Title and Picture layout.

slide = add(ppt,"Title and Picture");

Use the find method of the slide object to find the placeholder object that has the name Title.

titlePlaceholderObj = find(slide,"Title")
titlePlaceholderObj = 
  TextBoxPlaceholder with properties:

                 Bold: []
                 Font: []
    ComplexScriptFont: []
            FontColor: []
             FontSize: []
               Italic: []
               Strike: []
            Subscript: []
          Superscript: []
            Underline: []
      BackgroundColor: []
               VAlign: []
                 Name: 'Title'
                    X: []
                    Y: []
                Width: []
               Height: []
                Style: []
             Children: []
               Parent: [1×1 mlreportgen.ppt.Slide]
                  Tag: 'ppt.TextBoxPlaceholder:30:125'
                   Id: '30:125'

The find method returns an mlreportgen.ppt.TextBoxPlaceholder object.

Replace the placeholder content with the title text.

replace(titlePlaceholderObj,"Airplane");

Use the find method of the slide object to find the placeholder object that has the name Picture.

picturePlaceholderObj = find(slide,"Picture")
picturePlaceholderObj = 
  PicturePlaceholder with properties:

                 Bold: []
                 Font: []
    ComplexScriptFont: []
            FontColor: []
             FontSize: []
               Italic: []
               Strike: []
            Subscript: []
          Superscript: []
            Underline: []
      BackgroundColor: []
               VAlign: []
                 Name: 'Picture'
                    X: []
                    Y: []
                Width: []
               Height: []
                Style: []
             Children: []
               Parent: [1×1 mlreportgen.ppt.Slide]
                  Tag: 'ppt.PicturePlaceholder:31:126'
                   Id: '31:126'

The find method returns an mlreportgen.ppt.PicturePlaceholder object.

Replace the picture placeholder with a picture.

replace(picturePlaceholderObj,Picture("b747.jpg"));

Close and view the presentation.

close(ppt);
rptview(ppt);

PowerPoint® adjusts the picture dimensions to fit in the picture placeholder. If the picture placeholder dimensions are bigger than the Picture object dimensions, the picture stretches proportionally. If the dimensions are smaller, the picture is centered.

Input Arguments

expand all

Picture placeholder, specified as an mlreportgen.ppt.PicturePlaceholder object.

Picture to use as the replacement for the picture placeholder, specified as an mlreportgen.ppt.Picture object.

Output Arguments

expand all

Replacement picture, returned as an mlreportgen.ppt.Picture object.

Version History

Introduced in R2015b