MATLAB Answers

How can I add slides to an existing ppt presentation?

조회 수: 7(최근 30일)
Norman Matthews
Norman Matthews 2021년 7월 30일
댓글: Cris LaPierre 2021년 7월 30일
This is the code I am using but rather then adding a slide it replaces the existing slide:
slides = Presentation('PhaseNoiseData.pptx');
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);


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

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





Community Treasure Hunt

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

Start Hunting!

Translated by