PowerPoint presentation add images in loop from multiple files

Trying to write a GUI that goes into a folder and creates a powerpoint of each file into one large powerpoint using presentation generator and a Slide Master I created.
The problem I'm having is with plots/images. It persists in using the last plot created to replace all image content placeholders. I have tried multiple ways to loop through all with the same results. This is my latest attempt (using a slide master)
%% Create presentation....
for ii = 1:2 % this number will eventually be for the number of files in specified folder
slides = Presentation(slidesFile,slidesFile); % use pp just opened as new master
slides.OutputPath = fullfile(outdir,slidesFile); % where to place new Presentation
slides.TemplatePath = slides.OutputPath; % where to get template
%% Slide 1
images = {};
slide = add(slides,'S1');
%Title Change
iTitle = sprintf('Run Profile # %d',ii);
replace(slide, 'S1_Title',iTitle); % this works perfectly fine
%%% %Add plots to slides
%% To keep things simple I have been using simple plots but will eventually plot from each file
t = [55 55 621 946 168 ]';
p = [64546 4654 64546 64546 13113]';
% Plot
plot(t,p,'bo');
title(sprintf('Plot version: %d',ii)); %works perfectly fine
ylabel('yy');
xlabel('xx');
% convert plot to immage
img1 = sprintf('myPlot1%d.png',ii); % works perfectly fine. I can see my plots
saveas(f,img1);
% Replace the Content placeholder by the plot
images = [images {img1}];
replace(slides, 'S1_LeftPic', Picture(img1)); % Does not work. will put last plot image in both slides
close(slides); % I've put close slides both in and out of loop with same results
end
rptview(slides);
In debug mode it will show the correct image but puts last plot in both slots when finished. But will change the Title of slide correctly? I've tried just looping all in one go and this version which is opening and closeing and appending a pptx.

 Accepted Answer

Guys.
I figured it out.
I feel so dumb now
replace(slides, 'S1_LeftPic', Picture(img1)); % Does not work. will put last plot image in both slides
% it was that silly little 's' the end of slide!!!!!!!!! ugh :
replace(slide, 'S1_LeftPic', Picture(img1));

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!