MATLAB: Using MATLAB, how to edit the fields of a PPT I made in PowerPoint

apiexistingMATLABpptreplace

I have created a pptx in PowerPoint and I want to edit the text and such in MATLAB. How do I do this?

Best Answer

You have to reference the slide that the object is on and the content object name such as "Title 1". Example is below with attached "myPres.pptx".
In PowerPoint, you can see the content object names by going to Home>Select>Selection Pane. For example on a basic title page you might have "Title 1" and "Subtitle 2". If you know what these are you can refer to them directly:
%%Option 1: I know the name of the text box
import mlreportgen.ppt.*;
pptfile = 'myPres';
pres = Presentation(pptfile,pptfile); % Needs two inputs or it replaces the existing file with a new blank ppt

replace(pres,'Title 1','New Title Using Option 1') % 'Title 1' can be found in PPT
close(pres);
clear
If you do not already know the name, but know how the object is referenced as a child of the slide, you can access it through MATLAB:
%%Option 2: I know which text box to replace
import mlreportgen.ppt.*;
pptfile = 'myPres';
pres = Presentation(pptfile,pptfile); % Needs two inputs or it replaces the existing file with a new blank ppt
s = find(pres,''); % This will find all slides which do not already have an assigned name. So long as you did not assign a name to any slide, it will grab all of them
objName = s(1).Children(1).Name; % This will grab 'Title 1' (the name of the first child on the first slide)
replace(pres,objName,'New Title Using Option 2')
close(pres);
clear
For more information see the below documentation pages: