Main Content

replace

Class: mlreportgen.ppt.ContentPlaceholder
Package: mlreportgen.ppt

Replace content placeholder or content

Description

example

replacementContentObj = replace(contentPlaceholder,content) replaces the content of the ContentPlaceholder object or replaces the ContentPlaceholder object. If the content argument is a paragraph, the replace method replaces the content of the ContentPlaceholder by making the paragraph a child of the ContentPlaceholder object. If the content argument is a picture or a table, the replace method replaces the ContentPlaceholder object with an mlreportgen.ppt.Picture or mlreportgen.ppt.Table object, respectively.

replace(contentPlaceholder,paragraphs) replaces the content of a content placeholder with multiple paragraphs.

Examples

expand all

Add three Title and Content slides to a presentation. Replace the content placeholder of the first slide with text, the second slide with a table, and the third slide with a picture.

Import the PPT package 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("myContentPlaceholderPresentation.pptx");
open(ppt);

Add a slide with a Title and Content layout.

slide1 = add(ppt,"Title and Content");

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

titlePlaceholderObj1 = find(slide1,"Title")
titlePlaceholderObj1 = 
  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:15:40'
                   Id: '15:40'

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

Replace the placeholder content with the title text.

replace(titlePlaceholderObj1,"Content Replaced with Paragraph");

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

contentPlaceholderObj1 = find(slide1,"Content")
contentPlaceholderObj1 = 
  ContentPlaceholder with properties:

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

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

Replace the placeholder content with a paragraph.

replace(contentPlaceholderObj1,Paragraph("This is my paragaph"));

Add a second slide with a Title and Content layout.

slide2 = add(ppt,"Title and Content");

Replace the placeholder for the title with the title text.

titlePlaceholderObj2 = find(slide2,'Title');
replace(titlePlaceholderObj2,["Content Replaced with Table for" "Order 2 Magic Square"]);

Replace the content placeholder with a table.

contentPlaceholderObj2 = find(slide2,"Content");
replace(contentPlaceholderObj2,Table(magic(2)));

Add a third slide with a Title and Content layout.

slide3 = add(ppt,"Title and Content");

Replace the placeholder for the title with the title text.

titlePlaceholderObj3 = find(slide3,"Title");
replace(titlePlaceholderObj3,"Content Replaced with Picture of Peppers");

Replace the content placeholder with a picture.

contentPlaceholderObj3 = find(slide3,"Content");
replace(contentPlaceholderObj3,Picture("peppers.png"));

Close and view the presentation.

close(ppt);
rptview(ppt);

Here are the generated slides:

Input Arguments

expand all

Content placeholder, specified as an mlreportgen.ppt.ContentPlaceholder object.

Content to use as replacement, specified as a character vector, string scalar or one of these objects:

Multiple paragraphs to use as replacement, specified as one of these values:

  • String array

  • Cell array of any combination of string scalars, character vectors, or mlreportgen.ppt.Paragraph objects. Inner arrays are indented from outer arrays.

The slide layout determines whether the text displays as paragraphs, bullet list items, or numbered list items.

Output Arguments

expand all

Replacement content, returned as an mlreportgen.ppt.Paragraph, mlreportgen.ppt.Picture, or mlreportgen.ppt.Table object.

Introduced in R2015b