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"); open(ppt); 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,"title",para); replace(slide2,"content",["first item","second item","third item"]); close(ppt);
after you create the presentation, which is named myslides.pptx
,
you can open it.
rptview(ppt)
the generated presentation myslides.pptx
includes these two
slides.
update presentation content
ppt api programs generally include code that:
imports the
mlreportgen.ppt
api package. 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
the following code creates a presentation using the template from the presentation in the file
myslides.pptx
and overwritesmyslides.pptx
with the new presentation.
slidesfile = "myslides.pptx"; ppt = presentation(slidesfile, slidesfile); open(ppt);
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"); 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(ppt);
you can include code to open the presentation.
rptview(ppt)
the updated slide looks like this:
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 .
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 element | purpose |
---|---|
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. |