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

조회 수: 32 (최근 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