Main Content

replace

Class: mlreportgen.ppt.Slide
Namespace: mlreportgen.ppt

Replace text, tables, or pictures in a slide

Description

replace(slide,contentName,content) replaces the existing content in a slide content object with the specified content, which can be one or more paragraphs, a table, or a picture. If the type of content that you specify in the content argument is not valid for the content object identified by contentName, the replace method has no effect.

example

Examples

expand all

Use the replace method of an mlreportgen.ppt.Slide object to replace placeholder content with your content.

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. Add a slide for text, a slide for a picture, and a slide for a table.

ppt = Presentation('mySlideReplacePresentation.pptx');
slide1 = add(ppt,'Title and Content');
slide2 = add(ppt,'Title and Picture');
slide3 = add(ppt,'Title and Table');

In the first slide, replace the Title and Content placeholders with text.

replace(slide1,'Title','Text Slide');
replace(slide1,'Content','This is the content for slide 1');

In the second slide, replace the Title placeholder with text and the Picture placeholder with a picture.

replace(slide2,'Title','Picture Slide');
replace(slide2,'Picture',Picture('b747.jpg'));

In the third slide, replace the Title placeholder with text and the Table placeholder with a table.

replace(slide3,'Title','Table Slide');
replace(slide3,'Table',Table({1 2; 'a' 'b'}));

Close and view the presentation.

close(ppt);
rptview(ppt);

Here is the generated presentation:

Input Arguments

expand all

Slide to replace content in, specified as an mlreportgen.ppt.Slide object.

Name property value of the object that contains the content that you want to replace, specified as a character vector or string scalar.

When you add a slide to a presentation, the add method sets the Name property of the content objects on the slide based on the slide layout. See getLayoutNames. The Name property values include:

  • 'Title'

  • 'Content'

  • 'Table'

  • 'Picture'

  • 'Text'

  • 'Vertical Text'

The Name property can also be set to a custom value.

Replacement content, specified as one of these values:

  • character vector or string scalar

  • mlreportgen.ppt.Paragaph object

  • string array

  • mlreportgen.ppt.Table object

  • mlreportgen.ppt.Picture object

  • cell array of character vectors or Paragraph objects, or a combination of character vectors, strings scalars, string arrays, or mlreportgen.ppt.Paragraph objects. Contents of inner cell arrays or string arrays are indented from the contents of the outer cell array.

Version History

Introduced in R2015b