How to add image in existing ppt with matlab code

26 views (last 30 days)
I have standard powerpoint format in which I want to add graphs of different applications. and this procedure is repetative. so can someone tell me how can I do this with matlab code?
  1 Comment
Ashwini  More
Ashwini More on 28 Jan 2020
here is the code for open existing ppt and get the no of slides.
Now next task is that how can I replace figures by new figures from existing slides
Thank you in advance!!
clear all; clc;
project_dir = pwd(); %new
% List all current folder contents ending with .png. Resulting names will
% appear in the order returned by the operating system.
files = dir( fullfile(project_dir, '*.png')); %changed
% 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 amend
[fn, pn] = uigetfile('*.pptx', 'Select PowerPoint File To Amend');
filename = fullfile(pn, fn); %changed
Presentation = invoke(Presentation, 'open', filename);
% Get current number of slides
slide_count = get(Presentation.Slides, 'Count');

Sign in to comment.

Answers (1)

Selva Karna
Selva Karna on 28 Jan 2020
clc
clear all;
close all;
import mlreportgen.ppt.*
slidesFile = 'myPicturePresentation.pptx';
slides = Presentation(slidesFile);
add(slides,'Title Slide');
add(slides,'Title and Content');
plane = Picture(which('b747.jpg'));
plane.Width = '5in';
plane.Height = '2in';
replace(slides,'Content',plane);
close(slides);
  2 Comments
Walter Roberson
Walter Roberson on 28 Jan 2020
This requires the MATLAB Report Generator, I believe.
It would help if the code could show selecting a particular slide given the index.
Ashwini  More
Ashwini More on 28 Jan 2020
Edited: Ashwini More on 28 Jan 2020
I have tried this earlier but it does not completely apply to my application.
earlier code adds image in new slide but I want to add in only in existing slide
Is there any way by which I can add image to specific existing slide in specified location?
actually my task is to only update .png file into std format of ppt which is repetative work
my ppt format is of following type:
matlab.PNG

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!