MATLAB製作PPT(一):插入圖片

方法一:複製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);   % 原圖大小插入

參考:

  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

版權聲明:本文爲博主原創文章,未經博主允許不得轉載。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章