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

39 ビュー (過去 30 日間)
Andy L
Andy L 2014 年 8 月 20 日
編集済み: Ivan 2016 年 1 月 11 日
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 Center および File ExchangeMATLAB Report Generator についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by