How can I add slides to an existing ppt presentation?

조회 수: 35 (최근 30일)
Norman Matthews
Norman Matthews 2021년 7월 30일
편집: nailah oliver 2022년 1월 15일
This is the code I am using but rather then adding a slide it replaces the existing slide:
slides = Presentation('PhaseNoiseData.pptx');
open(slides);
slide = add(slides, 'Title and Picture');
plot1 = Picture('pn_plot.png');
slidetitle = sprintf('data_%s.pptx', datestr(now,'mm-dd-yyyy HH-MM'));
replace(slide, 'Title', slidetitle);
replace(slide, 'Picture',plot1);

답변 (2개)

Cris LaPierre
Cris LaPierre 2021년 7월 30일
I found this statement in the documentation:
"To add a slide, use the add method with an mlreportgen.ppt.Presentation object. For example, using the default PPT API template, you can add a slide using the Title and Content slide layout."
import mlreportgen.ppt.*;
slides = Presentation('myPresentation');
slide1 = add(slides,'Title and Content');
Try adding the import line to your code and see if that works.
  댓글 수: 2
Norman Matthews
Norman Matthews 2021년 7월 30일
The import line was in my code just above the code I showed. What I am trying to do is is to add a slide to the same ppt presentation everytime I run my app.
Cris LaPierre
Cris LaPierre 2021년 7월 30일
I may have jumped in over my head. The closest thing I could find that helped was this section of the Add Slide page. Basically, the report generator appears to be designed to create presentations, not modify existing ones. To get it to work, you need to be able to tell the method where to place the slide. Follow the instructions for how to assign a name to a slide in an existing presentation (Step #2, only has to be done once). Then follow the instructions in Step #3 for adding a new slide to the exiting pptx. This can be run multiple times. Each time it places the new slide before the named slide (I tested 3x).
Another option may be to use activeX. It has it's drawbacks as well. You can find a demo script and getting started instructions here.

댓글을 달려면 로그인하십시오.


nailah oliver
nailah oliver 2022년 1월 15일
편집: nailah oliver 2022년 1월 15일
To add a slide to an existing presentation, use the PowerPoint slides of interest as your powerpoint template when using the Presentation class. For example, your code would instead be:
%{
The second argument of the Presentation class is the template. The
template and the powerpoint are allowed to be the same, and the below
assignment will allow you to retain your old slides (because the old
slides are a part of the template) and your new slides.
%}
slides = Presentation('PhaseNoiseData.pptx','PhaseNoiseData.pptx'); % <-- corrected
open(slides) % not needed if you just want to add slides
slide = add(slides, 'Title and Picture');
plot1 = Picture('pn_plot.png');
slidetitle = sprintf('data_%s.pptx', datestr(now,'mm-dd-yyyy HH-MM'));
replace(slide, 'Title', slidetitle);
replace(slide, 'Picture',plot1);
close(slides) % needed to save slides
You should then see a new 'Title and Picture' slide with all the things you include with all your previous slides still there! Since you are using the slides of interest as your template, MATLAB assumes those existing slides are suppose to be there and therefore won't write over them.

카테고리

Help CenterFile Exchange에서 Create Complete PowerPoint Presentations에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by