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

21 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Samatha Aleti
Samatha Aleti el 27 de Abr. de 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 comentario
Connie Zhao
Connie Zhao el 27 de Abr. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Report Generator en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by