4.80769

4.8 | 27 ratings Rate this file 80 Downloads (last 30 days) File Size: 618 KB File ID: #19322

saveppt2

by Jedediah Frey

 

25 Mar 2008 (Updated 03 Jun 2010)

Save Matlab figure(s) to a PowerPoint Slide

| Watch this File

File Information
Description

saveppt2 builds on saveppt to include many new options.

Saveppt2 Features:
Save multiple plots to the same PowerPoint slide.
Create slides with and without a title.
Add notes to a PowerPoint slide
Scale the figure to fill the slide (with and without locking aspect ratio).
Horizontally and vertically align figures on the slide.
Use a template file for creating a new presentation. (Useful for automated reports)
Add padding to any of the sides for use with scaling or aligning figures.

New in Jun 2010.
Can choose between Metafile or bitmap drivers when copy and pasting to PowerPoint.
Add a blank title page or blank page from Matlab.
Add comments & textbox to slide.
Make PowerPoint visible during operations. (Required for Comments).
If there is another PowerPoint presentation open, PowerPoint will not quit.
Disable closing of PowerPoint presentation and return ActiveX object for further programmatic slide manipulation.

Also added a method to do batch processing by keeping an ActiveX session open and just adding new slides to it.
ppt=saveppt2('batch.ppt','init');
  for i=1:10
      plot(rand(1,100),rand(1,100),'*');
      saveppt2('ppt',ppt)
end
saveppt2('batch.ppt','ppt',ppt,'close');

The zip file includes saveppt2 and a sample presentation created with saveppt2. The code for creating the presentation is also included.
--
GitHub Project:
http://github.com/jedediahfrey/Jedediah-Frey-s-MATLABCentral-Projects

Acknowledgements

Saveppt, Xlswrite1, and Validate Input inspired this file.

MATLAB release MATLAB 7.5 (R2007b)
Other requirements Requires Windows because it uses ActiveX. This was tested on 2007b and Office 2000 on Windows XP SP3. It should work with other releases.
Tags for This File  
Everyone's Tags
automation, figure, graphics export(2), graphics import, plot, powerpoint(3)
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (35)
15 Nov 2012 Sachin  
21 May 2012 Naira  
11 May 2012 Rohit Mundra

Works really well on XP however it crashes MATLAB on my Windows 7 system (tried both, batch mode and otherwise) - I suspect it has something to do with the ActiveX controls...

29 Mar 2012 Sachin

Excellent tool.. really helps me a lot.

Is there any way, we can make this tool through a compiled Matlab code?

12 Jan 2012 Craig Remillard

@Manouch - I also get this error. It happens when I change the renderer from '' or 'painters' to 'opengl' or 'zbuffer':

It does not error out if I change -dmeta to -dbitmap in this line:

print('-dmeta',['-f' num2str(addlParms.figure(i))],rendOpt,resOpt);

BUT, then I have two other problems - first, the figures all become visible even though I have set them as not-visible (I assume there's a screen capture in bitmap print driver, because this happens when I just export figures to bitmap in Matlab as well). Second, all the bitmap figures in the PPT are solid black.

To summarize: the raster renderers crash out if I don't use -dbitmap, and they output black pictures and fill my screen if I don't. And the vector renderer (painters) doesn't crash with either option, but the vector images are insanely large for my dataset with -dmeta, and the raster images are still black blocks with -dbitmap. Can anyone offer a way to export raster images? I'll keep working on it and let y'all know if I figure it out.

27 Dec 2011 Hugh

Very useful already. Wonderful!

One revision suggestion. The chart in Matlab with date labels looking nice, but when exported to powerpoint, the date lables are crowded together. The resizing did not preserve the original look.

14 Dec 2011 Monica Barbu-McInnis

Awesome tool! I have a question about the 'template' keyword. I am specifying a template when creating a new ppt file of two figures, but the figures end up placed on a new slide while the first slide with the actual ppt template is blank. Am I missing any additional keywords?

31 Oct 2011 Carey Smith

Works nice & simple

16 Sep 2011 Nando Trindade

Awesome script! Is there a way to put an option to add a border around the figure? We had a different script that didn't work too well, but it had a line ppt_pic=op.Application.Windows.Item(1).Selection.ShapeRange.Item(1);
ppt_pic.Line.Visible = -1; I'm not sure how to replace the ppt_pic to use your code to add this border.

Also, is there a way to place the title in the template title slot instead of a position above the figure? Thanks for sharing.

15 Jul 2011 Jedediah Frey

Other requirements: Requires Windows because it uses ActiveX. This was tested on 2007b and Office 2000 on Windows XP SP3. It should work with other releases.

11 Jul 2011 Warwick

Attempting to run the first example, I get 'Error opening PowerPoint'. I'm using a Mac (R2011a and MS Office for Mac 2011 - is it likely this is the problem?

25 Apr 2011 Lan Du

powerful!

09 Mar 2011 Jonathan

Works great - very helpful tool!

04 Mar 2011 Andrew Wind

Just found this function following the Pick of the Week review of 2004 picks. It appears to work great thus far for figures. Is there any way to capture a GUI though? I can't seem to point it to the GUI even if all my other figures are closed. I would love to capture my Input GUI with all the values and then the results figures all in one ppt.

22 Dec 2010 Jedediah Frey

Unfortunately my company is sticking with Office 2000 for the near future and I only run OS X/Linux at home.

I will try and get to a computer with the latest office and see if I can fix that.

14 Dec 2010 Henik Vargas

Thank you for such an excellent and well coded function. Test automation in matlab would be incomplete without it. One minor question: Is it possible to save the file as pptx instead of ppt?

30 Sep 2010 Jedediah Frey

How are you calling the template? PowerPoint is complaining that it can't open the template file that you provide it.

09 Sep 2010 Danielle

I've used your script for several years now--it's great!

However, when trying to use the template argument, I get the following error:

322 op = invoke(ppt.Presentations,'Open',addlParms.template,[],[],0);
??? Invoke Error, Dispatch Exception:
Source: Microsoft Office PowerPoint 2007
Description: PowerPoint could not open the file.
Help File:
Help Context ID: 0

This has been a problem for both the v1 and v2 scripts. Any advice would be appreciated!

13 Aug 2010 Jedediah Frey

I'm only on Windows XP with Office 2000 and get no problems with surf or plot3 So it sounds like something with your setup.

Have you tried using the bitmap driver?

26 Jul 2010 Manouch

Unfortunately it doesn't work for me. But I think, it is my lack of knowledge about Matlab...
I tried to save a 3d-figure created with surf in a powerpoint file with saveppt2 an got the following message:

??? Invoke Error, Dispatch Exception:
Source: Microsoft Office PowerPoint 2007
Description: Shapes.Paste : Invalid request. Clipboard is empty or contains data which may not be pasted here.
Help File:
Help Context ID: 0

Error in ==> saveppt2 at 559
pic1 = invoke(new_slide.Shapes,'Paste');

I would appreciate, if anyone could tell me, what was my mistake.

Thanks in advance!

15 Mar 2010 Fergus

Precious time saver!

29 Jan 2010 john

Thanks for the great tool! I added the following code that lets you add text to a slide. (Not showing the argument parsing part) Someone with more experience with this can surely improve it.

% Add textbox if they are specified
if isfield(addlParms,'textbox')

% Convert \n and \t into characters for powerpoint
warning('off','MATLAB:strrep:InvalidInputType');
addlParms.textbox=strrep(addlParms.textbox,'\n',13);
addlParms.textbox=strrep(addlParms.textbox,'\t',9);

% Set layout of slide
new_slide.Layout='ppLayoutText';

% Set some handles
% I'm not sure what's different between TextFrame1 and TextFrame2
% But, the AutoSize property isn't available on TF1 (and it doesn't
% seem to matter if I add the actual text to TF1 or TF2.
tf1 = new_slide.Shapes.Placeholders(1).Item(2).TextFrame;
tf2 = new_slide.Shapes.Placeholders(1).Item(2).TextFrame2;

% Turn off bullets
tf1.TextRange.ParagraphFormat.Bullet.Type='ppBulletNone';

% Set text contents and font
tf2.TextRange.Font.Name = 'Courier New';

% Format paragraph, remove spaces between lines
pf = tf2.TextRange.ParagraphFormat;
set( pf, 'SpaceBefore', 0.2, ...
'SpaceWithin', 1, ...
'SpaceAfter', 0);

% Format shape so the text will be shrunken to fit in box
tf2.AutoSize='msoAutoSizeTextToFitShape';

% Finally, add the text
tf2.TextRange.Text = addlParms.textbox;

% I have no idea why I have to do this, if I don't the
% text does not resize.
ppt.visible=1;
op.NewWindow;
pause(2)
%fprintf('Autosize property is: %s\n', get(tf2, 'AutoSize'));
end

27 Jan 2010 Björn

Great great Tool,

have been using your ver. 1 for some time and just switched over to ver. 2. Short question though, do you have a script to easily export tables (or present matrices/cell arrays) from Matlab to ppt? I have been looking for a script for some time, but cannot find a really useful one...

Regards

11 Nov 2009 Paul

To avoid losing unsaved ppts, comment out this line:

invoke(ppt,'Quit');

(line 420 in 25 Mar 2008 version)

If you don't have any open ppt's, powerpoint will still close normally

[Tested using powerpoint ver 2007]

11 Nov 2009 Paul  
04 Nov 2009 Dan Selters  
20 May 2009 Jaroslaw Tuszynski

great improvement over saveppt . Thanks

18 Apr 2009 jhh

Works great.
One suggestion: you use
print('-dmeta'...;
to keep a figure's size unchanged,
print('-dbitmap',['-f' ...
should be used.
Perhaps add this as an extra option?

20 Mar 2009 Ameya Deoras

Saved me some time. Works with R2009a

14 Nov 2008 Wolfgang Schwanghart

Great function. The only minus is, that it automatically shuts down powerpoint and there is no warning. So unsaved ppts will be lost.

03 Nov 2008 Vincent Bonin  
23 Jun 2008 c garven

Thanks

01 Apr 2008 Nathan Brahms

Very nice! This will make my life easier...

28 Mar 2008 James Cai

Excellent

28 Mar 2008 D Selters

Outstanding!

Updates
24 Mar 2010

Added github repository.

03 Jun 2010

Update to version 3.5.
-
Incorporated suggestions in comments. In addition to code cleanup, minor bugs, 'workarounds' for ActiveX odd behavior.

Contact us