MATLAB making PPT (a): Insert Picture

Method a: Copy and paste figure +

The following code, easier to understand

%% 方法一:复制-粘贴
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  % 粘贴到当前

 

Method Two: Import known picture

 code show as below:

%% 方法二
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);   % 原图大小插入

reference:

  1. https://nl.mathworks.com/help/rptgen/ug/add-presentation-content.html
  2. https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2010/ff760731(v=office.14)
  3. https://blog.csdn.net/alsmile/article/details/20125641
  4. https://nl.mathworks.com/matlabcentral/answers/264558-how-do-i-add-multiple-png-files-to-an-existing-powerpoint-pptx-file-using-a-for-loop

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed.

Published 14 original articles · won praise 19 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_24694761/article/details/105334376