Mファイルスクリプト​によるPPTファイル​のスライドのコピー&​ペースト

21 views (last 30 days)
Hirokazu Masugami
Hirokazu Masugami on 5 Jun 2018
Answered: Hirokazu Masugami on 11 Jun 2018
Mファイルスクリプトを使ってPPTファイルを編集する際に、 スライドをコピー&ペーストするにはどうすればいいでしょうか?
イメージとしては まず、テンプレートとして使いたいPPTファイル(タイトルページとコンテンツページによる2ページ構成) を開き、 コンテンツページをコピー&ペーストして、その中に情報を埋め込み、 最後におそらく残ってしまうであろう空のコンテンツページ(ページコピーのコピー元用)を削除して、 PPTを保存するようなことをしたいと考えています。

Accepted Answer

Takashi Ueno
Takashi Ueno on 8 Jun 2018
MATLABでpptファイルを操作する場合、actxserverによってPowerPointのオートメーションサーバーを使用し、PowerPoint オブジェクトを操作することになります。
一例ですが、カレントディレクトリ上の'original.pptx'の2番目のスライドをコピーし、新規作成したスライドに挿入し、カレントディレクトリに'new.pptx'として保存する場合、以下のように行えます。
PowerPointのオブジェクトモデルを使用しているため、コマンドの詳細については、マイクロソフト社のリファレンス等をご参照ください。
% ActiveX オブジェクトを作成
ppt = actxserver('powerpoint.application');
ppt.Visible = 1;
% 新しいプレゼンテーションの作成
ppt_new=ppt.Presentations.Add();
% 新しいプレゼンテーションの0番目のスライドの後ろ(つまり1番目のスライド)に、
% 元のプレゼンテーションのi番目からj番目までのスライドをコピー
% 今回は2番目のスライドをコピー
ppt_new.Slides.InsertFromFile([pwd,'\original.pptx'],0,2,2);
% 保存
ppt_new.SaveAs([pwd,'\new.pptx'])
% 終了
ppt.Quit
ppt.delete

More Answers (1)

Hirokazu Masugami
Hirokazu Masugami on 11 Jun 2018
ご回答ありがとうございます。
テンプレートのPPTファイルを’original.pptx’とすると、 ’original.pptx’が2ページ構成で、1ページ目がTitleスライド、2ページ目がContentスライドにっていると想定します。 新しいスライドが’new.pptx’とすると、 ’new.pptx’は1ページ目が’original.pptx’のTitleスライドに情報を追加したもの、 2ページ目以降は’original.pptx’のContentスライドに情報を追加したものとすると、 以下のようにすればよろしいでしょうか?
% ActiveX オブジェクトを作成
ppt = actxserver('powerpoint.application');
ppt.Visible = 1;
% 新しいプレゼンテーションの作成
ppt_new=ppt.Presentations.Add();
% タイトルページの作成
ppt_new.Slides.InsertFromFile([pwd,'\original.pptx'],0,1,1);
i = 1
while dataEnd ~= 1
% コンテンツページの作成
slides = ppt_new.Slides.InsertFromFile([pwd,'\original.pptx'],i,2,2);
% スライドタイトルの設定
text=hs1.Title.TextFrame.TextRange;
set(text,'Text', [title_text, num2str(i)], 'Position',[10 10 10 10]))
% コンテンツの操作
hh = invoke(slides,'Item',i);
hs = hh.Shapes;
hp = invoke(hs,'AddTable', 3, 4, 60, 80, 600, 400);
hh = invoke(slides,'Item',i);
hs = hh.Shapes;
rect2 = [10 100 800 600];
set(figure(k),'Position',rect2)
hp = invoke(hs,'Paste');
set(hp,'Top',80)
set(hp,'Left',60)
hp = invoke(hs,'AddTable', 3, 4, 60, 80, 600, 400);
% ページ番号のインクリメント
i = i + 1;
end
% 保存
ppt_new.SaveAs([pwd,'\new.pptx'])
% 終了
ppt.Quit
ppt.delete
end

Communities

More Answers in the  Power Electronics Control

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!