Can I add a PNG file to an existing PowerPoinit presentation using MATLAB?

2 ビュー (過去 30 日間)
Brad
Brad 2017 年 2 月 12 日
I'm attempting to add a PNG file to slide 2 of an an existing 2-slide PowerPoint presentation using the following code;
% Clear out all workspace variables, close all open figures, and clear the
% command window
clear all;
close all;
clc;
% Create Common Object Model (COM) server so MATLAB can export data to
% PowerPoint
g = actxserver('powerpoint.application');
% Open PowerPoint and make it visible
g.Visible = 1;
Presentation = g.Presentation;
% Prompt the user for the PowerPoint file to open
[fn, pn] = uigetfile('*.ppt', 'Select PowerPoint File To Amend');
filename = fullfile(pn, fn);
Presentation = invoke(Presentation, 'open', filename);
% Get current number of slides
slide_count = get(Presentation.Slides, 'Count');
% Add Dice PNG to slide 2 in the existing Test slides file
slide_count = int32(double(slide_count));
PNG_To_Slide = invoke(Presentation.Slides, 'Add', slide_count, 1);
Image1 = PNG_To_Slide.Shapes.AddPicture('C:\Documents and Settings\My Documents\MATLAB\PNG_Dice.png', 'msoFalse', 'msoTrue', 0,75,620,440);
% Save PowerPoint presentation
Presentation.SaveAs('C:\Documents and Settings\My Documents\MATLAB\New_Slides.ppt');
% Close PowerPoint as a COM automation server
g.Quit;
g.delete;
While this does place the PNG file in the existing PowerPoint slides, I've had to add another slide just to do it. The result is a 3-slide PowerPoint file with the dice PNG on slide 2 of 3 - instead of slide 2 of 2.
Is it possible to add a PNG to an existing PowerPoint presentation without having to add a separate slide?

回答 (0 件)

カテゴリ

Find more on MATLAB Report Generator 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!

Translated by