Memo/Matlab

Matlab : Make & Write Data in PPT file (without PPT API)

_Ju 2022. 8. 9. 20:57

 

When you want to make and write data in PPT file (without API),

You can use this.

 

This example loads a pre-writed PPT template file and connects data to item ID values. (using VBA)


#PPT Template

 

 

# Code

DesktopPath = winqueryreg('HKEY_CURRENT_USER', 'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', 'Desktop');
PPTFile 	= 'PPT_Template.pptx';

%// Open PPT
p	= actxserver('PowerPoint.Application');
ppt	= p.Presentations.Open(strcat(DesktopPath, PPTFile));

%// Set Text
ppt.slides.Item(1).Shapes.Item(1).TextFrame.TextRange.Text = "New Title";
ppt.slides.Item(1).Shapes.Item(2).TextFrame.TextRange.Text = "New Sub_Title";

%// Delete Item
ppt.slides.Item(1).Shapes.Item(3).Delete;
ppt.slides.Item(1).Shapes.Item(4).Delete;
ppt.slides.Item(1).Shapes.Item(5).Delete;

%// Slide Duplicate
CopySlide1 = ppt.slides.Item(1).Duplicate;
CopySlide2 = ppt.slides.Item(1).Duplicate;
%// Another way to set text
set(CopySlide1.Shapes.Item(1).TextFrame.TextRange, 'Text', "New Title (in a New Slide)");

%// Slides Count
SlidesCount = ppt.slies.count;

%// Slides Move
CopySlide1.MoveTo(SlidesCount);

%// Add Picture. [Position 100 x 100, Size 200 x 200 (point)] 
img = strcat(DesktopPath, '\Img.png');
CopySlide1.Shapes.AddPicture(img, 'msoFalse', 'msoTrue', 100, 100, 200, 200);

%// Save ppt
NewPPTName = fullfile(DesktopPath, 'NewPPT.pptx');
ppt.SaveAs(NewPPTName);

 

You can refer other VBA methods here

https://docs.microsoft.com/en-us/office/vba/api/powerpoint.shapes.addpicture