方法一:复制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
版权声明:本文为博主原创文章,未经博主允许不得转载。