How to write a for loop to populate a powerpoint slide deck?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hayden Garmon
le 13 Août 2020
Modifié(e) : Prabhanjan Mentla
le 18 Août 2020
import mlreportgen.ppt.*
slides = Presentation('Waveform Plotting');
add(slides,'Title Slide',1);
contents = find(slides,'Title');
replace(contents(1),'Waveform Plotting');
add(slides,'Title and Content');
plane = Picture(which('JPG1.jpg'));
plane.Width = '4600';
plane.Height = '2100';
replace(slides,'Content',plane);
add(slides,'Title and Content');
plane = Picture(which('JPG2.jpg'));
plane.Width = '4600';
plane.Height = '2100';
replace(slides,'Content',plane);
close(slides);
Hi All,
I am trying to read an entire directory and then create and fill a powerpoint with each slide containing one, full screen, jpg from the directory. My largest struggle is creating the powerpoint. Right now, the code seen above writes a power point with a title slide, but it duplicates the first slide into two slides, instead of using a different JPG for each subsequent slide.
0 commentaires
Réponse acceptée
Prabhanjan Mentla
le 17 Août 2020
Modifié(e) : Prabhanjan Mentla
le 18 Août 2020
Hi
You can do by iterating through all the files of images from a directory and adding them to the slides in the ppt using Picture function. For example, consider the below lines of code:
import mlreportgen.ppt.*
ppt = Presentation('myPresentation.pptx');
open(ppt);
files = dir('*.png');
for i=1:length(files)
pictureSlide = add(ppt,'Blank');
img = Picture(sprintf('image%d.png',i));
add(pictureSlide,img);
end
close(ppt);
The images in the directory are of image1.png,image2.png...etc.,
For more information refer the below link.
Hope this helps.
Update: Even if the images are of different names we may achieve the above task by replacing the
img = Picture(sprintf('image%d.png',i)); line with img = Picture(files(i).name).
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Update PowerPoint Presentation Content dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!