How can I copy a figure containing into a powerpoint slide created with activex?

21 ビュー (過去 30 日間)
I am trying to paste a figure that I have copied in my clipboard onto a slide within a for loop and I keep erroring out. Here is my code:
for i=1:20
fh=fig
%code code code
%plot
print(gcf,'-dmeta'); %copy figure to clipboard
%create powerpoint and new slide
ppt = actxserver('PowerPoint.Application');
ppt.Visible = 1;
ppt.Presentations.Add()
layout = ppt.ActivePresentation.SlideMaster.CustomLayouts.Item(2);
ppt.ActivePresentation.Slides.AddSlide(1, layout);
%paste?
ppt.selection.PasteSpecial(0,0,1,0,3) %error, not valid
end

採用された回答

Samatha Aleti
Samatha Aleti 2020 年 4 月 27 日
Hi,
As per my understanding you are trying to copy figure to clipboard and paste in PowerPoint slide. Here is a sample code to do this:
% Plot a figure.
fig = figure();
plot(1:10, 2:2:20,'*b');
ppt = actxserver('PowerPoint.Application');
% Assuming there is a PPT (with at least 1 slide) open
activePPT = get(ppt, 'ActivePresentation');
% Slides
slides = activePPT.Slides;
slide = slides.Item(1); % Select a slide
slide.Select;
% Shapes
shapes = slide.Shapes;
shape = shapes.Item(2); % Select an area
shape.Select;
% Copy figure
print(fig, '-clipboard', '-dmeta')
% Paste
pasted_shape = shapes.PasteSpecial(2);
  1 件のコメント
Connie Zhao
Connie Zhao 2020 年 4 月 27 日
I am getting this error when executing the paste:
Error using
Interface.91493475_5A91_11CF_8700_00AA0060263B/PasteSpecial
Invoke Error, Dispatch Exception:
Source: Microsoft PowerPoint
Description: Shapes.PasteSpecial : Invalid request. The
specified data type is unavailable.
Help File:
Help Context ID: 0

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Report Generator についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by