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

20 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Samatha Aleti
Samatha Aleti le 27 Avr 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 commentaire
Connie Zhao
Connie Zhao le 27 Avr 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Report Generator dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by