Main Content

Create a Presentation Generator

You can use the MATLAB® API for PowerPoint® (PPT API) to update and create PowerPoint presentations programmatically. For example, this MATLAB script creates a presentation that has a title page and one content slide with a bulleted list.

import mlreportgen.ppt.*;

ppt = Presentation("mySlides.pptx");
slide1 = add(ppt,"Title Slide");
replace(slide1,"Title",'My Presentation');
replace(slide1,"Subtitle","Create a Presentation Program");
slide2 = add(ppt,"Title and Content");
para = Paragraph("First Content Slide");
para.FontColor = "blue";
replace(slide2,"Content",["First item","Second item","Third item"]);

After you create the presentation, which is named MySlides.pptx, you can open it.


The generated presentation MySlides.pptx includes these two slides.

First slide with the title "My Presentation" and subtitle "Create a Presentation Program". Second slide with a blue title "First Content Slide" and a bulleted list with the items: "First item", "Second item", and "Third item".

Update Presentation Content

PPT API programs generally include code that:

  • Imports the mlreportgen.ppt API namespace to avoid using long, fully qualified class names.

    import mlreportgen.ppt.*;
  • Creates a Presentation object to:

    • Hold the presentation contents

    • Specify the output location for the generated presentation

    • Indicate the PowerPoint template

      The following code creates a presentation using the template from the presentation in the file mySlides.pptx and overwrites mySlides.pptx with the new presentation.

    slidesFile = "mySlides.pptx";
    ppt = Presentation(slidesFile, slidesFile);
  • Adds or replaces slide content.

    slide2 = ppt.Children(2);
    contents = find(slide2,"Title");
    replace(contents,Paragraph("Modified Content Slide"));
    contents = find(slide2,"Content");
    datePara = Paragraph("Fourth item: Updated item");

    The PPT API replaces PowerPoint template placeholders with content defined in the program. In the template, you can interactively add placeholders or rename placeholders for your program to interact with.

  • Closes the presentation, which generates the content and formatting of the presentation.


You can include code to open the presentation.


The updated slide looks like this:

Slide two with the title "Modified Content Slide" and four bulleted items: "First item", "Second item", "Third item", and "Fourth item: Updated item"

To see another example of a PPT API program, see Generate a Presentation From the Results of a MATLAB Application.

Two Ways to Use the PPT API

You can create a PPT API program that:

  • Replaces content in, or adds content to, an existing PowerPoint presentation

  • Generates a complete PowerPoint presentation

Add Content to an Existing Presentation

To add or update content to an existing presentation without manually updating the presentation each time content changes, use the PPT API. This approach is useful when you want to use most of the content and formatting in an existing presentation.

  • You can use the PPT API and MATLAB functions to generate content for a presentation from MATLAB code and Simulink® models.

  • You can update a presentation by overwriting the presentation file or create a separate version of the presentation with a different presentation name.

Create a Complete Presentation

To create a complete presentation when you want to use the same content using multiple PowerPoint templates, use the PPT API.

PPT API Applications and PowerPoint Templates

The PPT API uses PowerPoint presentations as templates to generate presentations. Templates allow you to specify the fixed content and default layout and appearance of the slides in your presentations. Your MATLAB program can use the PPT API to override the default layout and format of specific slides.

The template can be an empty presentation or a presentation with slides. You can use the following as templates for a PPT API presentation:

  • The default PPT API PowerPoint template

  • A customized copy of the default PPT API PowerPoint template

  • An existing PowerPoint presentation whose content you want to update

  • A PowerPoint template that you create or update interactively in PowerPoint

See Set Up a PowerPoint Presentation Template.

Template Elements

PowerPoint templates include several elements that the PPT API uses to generate a presentation. To customize formatting defined in a template, modify one or more of these template elements.

PowerPoint Template ElementPurpose

Slide masters

Applies the slide master formatting globally to the presentation. Specifies a layout and formats common to a set of slide layouts

Slide layouts

Specifies a variant of a slide master layout.

Table styles

Specifies the default appearance of a table. PowerPoint defines a standard set of table styles. You cannot modify these styles but you can use the PPT API to apply these styles to tables you create and override the styles for particular tables.


Specifies an area of a slide layout that you can replace with text, a list, picture, table, or other content. Every placeholder has a name. You can use PowerPoint interactively to assign a name to a placeholder. You can then use the name in your PPT program to replace the placeholder with content.

Related Topics