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

Replace content placeholder or its content



contentObj = replace(ContentPlaceholder,content) replaces the content of the ContentPlaceholder object or replaces the ContentPlaceholder object. If content is a paragraph, it replaces the placeholder content. If content is a table or a picture, it replaces the placeholder object.


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


Replace Content Placeholders Using Paragraph and Table Objects

The type of object you use to replace a content placeholder determines whether the object replaces the placeholder’s content or the entire placeholder. Using a paragraph replaces the content. Using a table or a picture replaces the entire placeholder. This example shows how to use the mlreportgen.ppt.ContentPlaceholder.replace method and what happens to the ContentPlaceholder object based on the object you replace it with.

Create a presentation and add two Title and Content slides from the default template. Return the instances of the ContentPlaceholder object 'Content' and assign them to a variable. The contents variable is an array.

import mlreportgen.ppt.*

slides = Presentation('MyPresentation');

add(slides,'Title and Content');
add(slides,'Title and Content');

contents = find(slides,'Content');

Replace the first 'Content' object in the array using a table. Replace the second 'Content' object using a paragraph. Return the updated instances of the 'Content' objects and update the variable with the new objects.


contents = find(slides,'Content');

Display the class of each of the 'Content' objects in the contents array. The placeholder you replaced using a table is a Table object. The placeholder you replaced using a paragraph is a ContentPlaceholder object that contains the new paragraph.


Because the second object is still a placeholder object, you can replace the contents again.


Because the first object is no longer a ContentPlaceholder object, you can replace it only with an object of the same type, in this case a table. Replacing it with a paragraph or picture returns an error.

Replace the Content Placeholder Content with Multiple Paragraphs

Create a presentation.

import mlreportgen.ppt.*
name1 = 'before';
slides = Presentation(name1);

The default PPT API PowerPoint® template Comparison slide layout has a Left Content and a Right Content placeholder. Replace the content in those content placeholders. Then generate the presentation.

replace(slides,'Left Content','dummy content');
replace(slides,'Right Content','dummy content');

Create a second presentation, using the first presentation as the template.

name2 = 'after';
slides = Presentation(name2,name1);

Use the find method with the Presentation object to return content objects named Left Content and Right Content.

left = find(slides,'Left Content');
right = find(slides,'Right Content');

Replace the left and right content.

para = replace(left(1),'Left item in the list');
para.Italic = true;
para.FontColor = 'green';
replace(right(1), { ...
    'Right List item', ...
        {'Inner right list item','Other inner right list item'}...
    'Right List item', ...

Generate the presentation and then open myBoldPresentation.pptx. On a Windows® platform, you can open the presentation in MATLAB®:

if ispc

Input Arguments

expand all

Content placeholder to replace content or whose content to replace, specified as an mlreportgen.ppt.ContentPlaceholder object.

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

  • mlreportgen.ppt.Paragraph

  • mlreportgen.ppt.Table

  • mlreportgen.ppt.Picture

Paragraphs to replace placeholder content with, specified as a cell array of character vectors, mlreportgen.ppt.Paragraph objects, or a combination of both. Inner cell arrays specify inner list items. The slide layout determines whether the text displays as paragraphs, bullet list items, or numbered list items.

Example: {'My first paragraph','My second paragraph'}

Output Arguments

expand all

Content object, returned as an mlreportgen.ppt.Paragraph, mlreportgen.ppt.Table, or mlreportgen.ppt.Picture object. The output object corresponds to the character vector or content object that you specify with the content input argument.

Introduced in R2015b