This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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.*;
 
slidesFile = 'mySlides.pptx';
slides = Presentation(slidesFile);
 
slide1 = add(slides,'Title Slide');
replace(slide1,'Title','My Presentation');
replace(slide1,'Subtitle','Create a Presentation Program');
 
slide2 = add(slides,'Title and Content');
para = Paragraph('First Content Slide');
para.FontColor = 'blue';
replace(slide2,'Title',para);
 
replace(slide2,'Content',{'First item','Second item','Third item'});
 
close(slides);

After you create the presentation, which is named MySlides.pptx, you can open it. On a Windows® platform, you can open the presentation in MATLAB:

if ispc
    winopen(slidesFile);
end

The generated presentation MySlides.pptx includes these two slides.

PPT API Programs

PPT API programs generally include code that:

  • Imports the mlreportgen.ppt API package. Include an import statement. To omit the package name when you invoke PPT API object constructors and method, import the package.

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

    • Hold the presentation contents

    • Specify the output location for the generated presentation

    • Indicate the PowerPoint template

    slidesFile = 'mySlides.pptx';
    slides = Presentation(slidesFile);
    
  • Adds or replaces slide content.

    contents = find(slide2,'Title');
    replace(contents,Paragraph('First Content Slide'));
    
    contents = find(slide2,'Content');
    datePara = Paragraph('Today is ');
    dateText = date;
    append(datePara,dateText);
    add(contents,datePara);
    

    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.

    close(slides);

You can include code to open the presentation on Windows platforms. Use winopen with the name of the file, which in this case is stored in the slidesFile variable.

if ispc
    winopen(slidesFile);
end

To see another example of a PPT API program in MATLAB, enter population_slides. (To run this example on Linux®, you must have Open Office software installed.)

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. 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

  • An existing PowerPoint presentation whose content you want to update

  • A PowerPoint template

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 PPT API comes with a default template that you can use to create presentations. If the default template does not meet your needs, you can use PowerPoint interactively to create templates that do meet your needs.

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.

Placeholders

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