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

21 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Samatha Aleti
Samatha Aleti am 27 Apr. 2020
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 Kommentar
Connie Zhao
Connie Zhao am 27 Apr. 2020
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB Report Generator finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by