Main Content

replace

Class: mlreportgen.ppt.TemplatePicture
Namespace: mlreportgen.ppt

Replace template picture with another picture

Syntax

newPicture = replace(templatePicture,replacementPicture)

Description

newPicture = replace(templatePicture,replacementPicture) replaces a template picture with another picture.

Input Arguments

expand all

Template picture to replace, specified as an mlreportgen.ppt.TemplatePicture object.

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

Output Arguments

expand all

New picture in the presentation slide, specified as an mlreportgen.ppt.Picture object.

Examples

expand all

If you create a presentation from an existing presentation, a picture from the existing presentation (a template picture) is represented by an mlreportgen.ppt.TemplatePicture object. You can change the position, width, and height of the template picture by setting properties of the object. You can also modify the XML markup of the template picture. To replace the template picture, use the replace method of the TemplatePicture object. For example, suppose that you create a presentation from an existing presentation myPresentation that has a slide with the 'Title and Picture' layout. The following code replaces the template picture with a different picture.

Generate a presentation, MyPicturePresentation, that you then use as the template presentation for another presentation. MyPicturePresentation has one slide with one picture.

import mlreportgen.ppt.*
ppt = Presentation("MyPicturePresentation");
open(ppt);
slide1 = add(ppt,"Title and Picture");
replace(slide1,"Title","Street");
replace(slide1,"Picture",Picture("street1.jpg"));

Close and view the presentation.

close(ppt);

Create a presentation, MyNewPicturePresentation, from MyPicturePresentation. MyPicturePresentation is the template presentation for MyNewPicturePresentation,

ppt = Presentation("MyNewPicturePresentation","MyPicturePresentation");
open(ppt);

Find the template picture by using the find method of the slide object. Because the picture comes from a template presentation slide, find returns the picture as an mlreportgen.ppt.TemplatePicture object.

slide1 = ppt.Children(1);
templatePictureObj = find(slide1,"Picture") 
templatePictureObj = 
  TemplatePicture with properties:

    XMLMarkup: '<p:pic><p:nvPicPr><p:cNvPr id="8" name="Picture"/><p:cNvPicPr><a:picLocks noChangeAspect="1" noGrp="1"/></p:cNvPicPr><p:nvPr><p:ph idx="13" sz="quarter" type="pic"/></p:nvPr></p:nvPicPr><p:blipFill><a:blip r:embed="rId2"><a:extLst><a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}"><a14:useLocalDpi val="0" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main"/></a:ext></a:extLst></a:blip><a:stretch><a:fillRect/></a:stretch></p:blipFill><p:spPr/></p:pic>'
         Name: 'Picture'
            X: []
            Y: []
        Width: []
       Height: []
        Style: []
     Children: []
       Parent: [1×1 mlreportgen.ppt.Slide]
          Tag: 'ppt.TemplatePicture:70:263'
           Id: '70:263'

Replace the picture with a different picture.

street2 = Picture("street2.jpg");
replace(templatePictureObj,street2);

Close and view the presentation.

close(ppt);
rptview(ppt);

Version History

Introduced in R2019b