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

To add new slides to an existing PowerPoint presentation with the help of mlreportgen.ppt in MATLAB, you can use the following code:

main.m
% Create a PowerPoint presentation object 
ppt = Presentation('existing_presentation.pptx');

% Get the number of existing slides
numSlides = getNumberOfSlides(ppt);

% Create a for loop to add new slides 
for ii = 1:5 % Add 5 new slides
    slide = add(ppt,'Title and Content'); % Create a new slide of 'Title and Content' layout
    replace(slide,'Title',['New Slide ' num2str(numSlides + ii)]); % Set the title of the slide
    replace(slide,'Content','This is a new slide added using MATLAB.'); % Set the content of the slide
end

% Close the presentation
close(ppt);
572 chars
16 lines

In this code, we first create a Presentation object by passing the filename of the existing PowerPoint presentation to Presentation. We then use the getNumberOfSlides function to get the number of existing slides in the presentation.

We create a for loop that iterates 5 times (you can change this number to add more or fewer slides) to create new slides using the add function. The add function takes the presentation object and the name of the slide layout as inputs. In this case, we're using the 'Title and Content' layout.

We use the replace function to set the title and content of each new slide. The first argument of replace is the slide object, and the second argument is the name of the placeholder to replace. The third argument is the text that we want to replace the placeholder with.

Finally, we close the presentation using the close function.

Note: Make sure to have mlreportgen.ppt installed and added to the path before running the code.

related categories

gistlibby LogSnag