add new slides to an existing powerpoint with the help of a while loop and mlreportgen.ppt in matlab

You can use the Presentation.add method of mlreportgen.ppt.Presentation to add new slides to an existing PowerPoint presentation in Matlab. You can use a while loop to add multiple slides to the presentation. Here's an example code:

main.m
import mlreportgen.ppt.*

% Open the existing PowerPoint presentation
ppt = Presentation('existing_presentation.pptx');

% Determine the total number of slides in the presentation
slide_num = length(ppt.SlideMaster.SlideLayout);

% Define the number of slides to add
slides_to_add = 5;

% Use a while loop to add new slides to the presentation
while slides_to_add > 0
    % Determine the layout index of the next slide
    layout_index = mod(slide_num, length(ppt.SlideMaster.SlideLayout)) + 1;
    
    % Add a new slide using the next layout
    slide = add(ppt, ppt.SlideMaster.SlideLayout(layout_index));
    
    % Add content to the new slide
    title = Text('New Slide');
    add(slide, title);
    
    % Decrement the slides_to_add counter
    slides_to_add = slides_to_add - 1;
    
    % Increment the slide_num counter
    slide_num = slide_num + 1;
end

% Save the modified presentation
save(ppt);
912 chars
33 lines

This code opens an existing PowerPoint presentation (existing_presentation.pptx), determines the total number of slides in the presentation, and adds five new slides to the presentation using a while loop. The while loop determines the layout index of the next slide based on the current slide number, adds a new slide using the corresponding layout, adds a title to the new slide, and decrements the slides_to_add counter until it reaches zero. Finally, the modified presentation is saved.

gistlibby LogSnag