方法一:複製figure+粘貼
代碼如下,比較好理解
%% 方法一:複製-粘貼
clear;clc;
filename = 'C:\Users\Administrator\Desktop\Template.pptx'; % ppt路徑
g = actxserver('powerpoint.application');
g.Visible = 1; % 可視化
Presentation = g.Presentation;
Presentation = invoke(Presentation, 'open', filename);
slide_count = get(Presentation.Slides, 'Count'); % 當前ppt頁數
slide_count = int32(double(slide_count)+1); % 下一頁
slide = invoke(Presentation.Slides,'Add',slide_count,11); % 增加空白頁
H = figure('color',[1,1,1]); % 作圖
plot(1,1,'o');
hgexport(H,'-clipboard'); % 圖片複製到粘貼板
slide.Shapes.Paste % 粘貼到當前
方法二:導入已知圖片
代碼如下:
%% 方法二
clear;clc;
filename = 'C:\Users\Administrator\Desktop\Template.pptx'; % ppt路徑
g = actxserver('powerpoint.application');
g.Visible = 1; % 可視化
Presentation = g.Presentation;
Presentation = invoke(Presentation, 'open', filename);
slide_count = get(Presentation.Slides, 'Count'); % 當前ppt頁數
slide_count = int32(double(slide_count)+1); % 下一頁
slide = invoke(Presentation.Slides,'Add',slide_count,11); % 增加空白頁
FiguesFilePath = 'C:\Users\Administrator\Desktop\Test.jpg'; % 圖片路徑
slide.Shapes.AddPicture(FiguesFilePath, 'msoFalse', 'msoTrue', 0,0,-1,-1); % 原圖大小插入
參考:
- https://nl.mathworks.com/help/rptgen/ug/add-presentation-content.html
- https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2010/ff760731(v=office.14)
- https://blog.csdn.net/alsmile/article/details/20125641
- https://nl.mathworks.com/matlabcentral/answers/264558-how-do-i-add-multiple-png-files-to-an-existing-powerpoint-pptx-file-using-a-for-loop
版權聲明:本文爲博主原創文章,未經博主允許不得轉載。