How Can I Access Individual Powerpoint Shapes from a collection; actxserver COM objects

35 次查看(过去 30 天)
Hello All,
First time question asker!
I am trying to access multiple shapes (Title and Subtitle) one at a time in order to edit them in a PowerPoint presentation through the actxserver. However the collection of shapes does not seem to let me access the individual shapes - I have tried using indexing to access a specific shape but get the obvious index error below:
Index exceeds matrix dimensions.
I have read that accessing collections in MATLAB is a known issue, however I did not manage to find any solution - I am assuming it will involve the get command but I'm afraid I just haven't cracked it yet.
My code is as such:
%%Start an ActiveX session with PowerPoint:
ppt = actxserver('PowerPoint.Application');
ppt.Visible = 1;
pres = ppt.Presentations.Add;
% Apply Template
invoke(pres,'ApplyTemplate', template);
% Title Slide
title_slide = invoke(pres.Slides,'Add',1,1);
% This section works but only gives me access to the main title
title_shapes = get(title_slide.Shapes);
title = get(title_shapes.Title);
set(title.TextFrame.TextRange,'Text',main);
% When I try with the following line the error above is generated.
title_shape = get(title_slide.Shapes(1));
The rest of the code is not written (this is WIP) and the function is finished with the usual
% Quit PowerPoint
invoke(ppt,'Quit');
% End process
delete(ppt);
clear ppt pres;
The first slide invoked is a 'title' slide (containing title & subtitle). The template is simply a file with our company logo and not important. I am using MATLAB 2014a, and PowerPoint 2010.
If anyone can offer any advice/direction on how to access the shape it would be greatly appreciated!
Thanks, Andy

采纳的回答

Andy L
Andy L 2014-8-21
编辑:Andy L 2014-8-21
Solved it!
Individual Shapes from the Shapes collection are accessed as Items. For a collection of two shapes (title and subtitle) I used the following code.
title_slide = invoke( pres.Slides,'Add',1,1 ); % Add Title Slide
title = get( title_slide.Shapes.Item(1) ); % Get Handle to title shape
subtitle = get( title_slide.Shapes.Item(2) ); % Get Handle to subtitle shape
set(title.TextFrame.TextRange ,'Text','Title' ); % Set Title Text to 'Title'
set(subtitle.TextFrame.TextRange,'Text','Subtitle'); % Set Subtitle Text to 'Subitle'
  1 个评论
Ivan
Ivan 2016-1-11
编辑:Ivan 2016-1-11
Thanks! Same can be used by predefined slides:
h = actxserver('PowerPoint.Application');
Presentation = h.Presentation.Open('YourPresentation.pptx');
Slide1 = Presentation.Slides.Item(1);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Report Generator 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by