4.88235

4.9 | 18 ratings Rate this file 122 Downloads (last 30 days) File Size: 19.1 KB File ID: #30124
image thumbnail

Smart PowerPoint Exporter

by

 

21 Jan 2011 (Updated )

Exports Matlab figures to PowerPoint. Fixes formatting directly in PowerPoint to allow easy editing.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

This program exports a Matlab figure to PowerPoint and converts it into a group of PowerPoint objects. It then edits various object properties directly in PowerPoint, such that the figure can be easily modified without disrupting appearance, alignment, etc.

Program features:
(See Screenshot for summary)

- Exports using an added button on the Matlab toolbar or using command line code.

- Applies proper alignment and anchoring to all axis labels, tick labels and text boxes, such that they don't become misaligned following figure resizing or font changes in PowerPoint.

- Identifies logarithmic and scientific notation axes and applies superscripts in PowerPoint. This prevents the splitting of each superscripted label into two text boxes, which occurs during standard copy-pasting into PowerPoint.

- Converts each TEX-formatted textbox into a single properly formatted PowerPoint textbox. This prevents the splitting of TEX boxes into multiple objects. Converts all special TEX characters to Unicode.

- Removes unnecessary background color/outline objects that result from standard copy-pasting and instead edits these PowerPoint features directly.

- Combines pieces of each trace into a single PowerPoint group object to allow easy editing.

- Allows exporting object-dense parts of the figure as bitmaps, while leaving other parts in editable metafile format.

- Allows specifying the image resolution of both metafile and bitmap figure parts.

- Allows specifying the PowerPoint slide to which the figure is exported.

- Allows specifying the size and position of the exported figure.

- Allows grouping objects for speed and bulk-editing in PowerPoint.

Acknowledgements

Saveppt inspired this file.

MATLAB release MATLAB 7.10 (R2010a)
Other requirements - Windows - Tested in Microsoft PowerPoint 2010
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (34)
23 Jun 2014 Cris

I just found this nice workaround Eric Sampson posted in the comments to 'saveppt2' to work flawlessly with 'pptfigure' and PowerPoint 2013 as well.

Here follows his orginal comment:

----

Hi all, for those of you who are encountering an error when using this function with PowerPoint 2013, to correct this issue you can replace the following line:
pic1 = invoke(new_slide.Shapes,'Paste');

with the following two lines:

picShapeRange = invoke(new_slide.Shapes,'Paste');
pic1 = invoke(picShapeRange,'Item',1);

This fix will still work when using older versions of PowerPoint.

----

Everything I did was to modify it as follows and everything worked as before:

picShapeRange = invoke(new_slide.Shapes,'Paste'); % or: picShapeRange = invoke(slide.Shapes,'PasteSpecial', 3); (as required)
pic = invoke(picShapeRange,'Item',1);

Best regards,
Cris

19 Jun 2014 Laurel

Not yet... I can only get this working by having a 2007 Powerpoint open, then converting the slide to PowerPoint 2013. It's not exactly elegant but it does work. The issue seems to be the call to actxserver is designed to work with an older version of ppt.

19 Jun 2014 Yair Churi

Laurel, its seems like I am seeing the same failure. Were you able to resolve this?

Error using Interface.9149347A_5A91_11CF_8700_00AA0060263B/get
Error: Object returned error code: 0x800A01A8

Error in pptfigure (line 564)
metaWidth = get(pic,'Width');

10 Jun 2014 Laurel

I am having the same issue as Diego.
I am running Matlab R2014a on a Windows 7 OS, trying to interact with Powerpoint 2013.
I get the following error:

Error using Interface.Microsoft_PowerPoint_12.0_Object_Library.ShapeRange/get
Error: Object returned error code: 0x800A01A8

Error in pptfigure (line 564)
metaWidth = get(pic,'Width');

Error while evaluating uipushtool ClickedCallback

Does anyone know what changed with the newer PPT versions? I would really like to use this function.

24 Apr 2014 Julian Hapke

I think the feature('COM_SafeArraySingleDim', 1)
should be reset to 0 when the function is done, so matlabs default behavior is restored

21 Apr 2014 Carl Witthoft

Perhaps should include a warning that plots will be dumped to the currently open PPT document :-) . Love the option to execute from the command line (rather than via button), thus allowing automated scripting of multiple plots.
Also very handy, but hidden in the html doc page: ability to place new PPT page at current location in (an open) PPT doc, rather than appending to the existing slide set.

22 Nov 2013 Jens Richter

Hey,

I recently discovered this nice script, what is unfortunately not complety up to date in terms of compatibility and indeed sometimes pretty hard to use.
Anyway great work. I also was facing different problems. Most of them could be solved with the help of this thread and belive it or not with the fu**ing manual :-D

I also where able to "understand and work arround" one problem that some of you mentioned:

??? Invoke Error, Dispatch Exception:
Source: Microsoft PowerPoint 2010
Description: ShapeRange.Item : Integer out of range. 2 is not in Index's valid range of 1 to 1.
Help File:
Help Context ID: 0

It seems that this most likely happens when the number of points in your plot is to high. This happened to me when I used pcolor with a big amount of data points.
A work arround is simply to export this graph as image via (lets assume it's figure1):

pptfigure(figure1,'BitmapResolution',200);

% 200 indicates the resolution

You also can use other properties for 'BitmapResolution' => Have a look into the manual ;-)

Best,
Jens

22 Nov 2013 Alex Tayler

Frederic, it's unsatisfying but if you simply comment out line 961 the program works with newer version of powerpoint.

17 Oct 2013 Frederic

I used pptfigure to copy figures and it worked pretty well. But for some weeks it appears that it doesn't work anymore and I get the following error message:

Error using Interface.9149347F_5A91_11CF_8700_00AA0060263B/set
Invoke Error, Dispatch Exception: Erreur non spécifiée

Error in pptfigure (line 961)
set(lineObj,'Weight',get(objects(obj),'linewidth'));
Does anyone have an idee on how to fix this problem?
Thank you in advance

12 Sep 2013 Rhymer Yang

I used to copy figure to PowerPoint, ungroup it, edit objects and group them again; very tedious. This function does all these automatically! It's AWESOME! Works like a charm! Thanks for the great work!

29 Jul 2013 Scott

Very useful!

29 Jun 2013 Nevzus

Hello,
I am looking for this kind of application everywhere but cannot find a version that works for Mac. Can this be made to work for Mac as well?
Thanks, - NG

22 Apr 2013 Diego

Hello,

Im using matalb 2012b and powerpoint 2013. I try to use this but I get

"Error using Interface.9149347A_5A91_11CF_8700_00AA0060263B/get
Error: Object returned error code: 0x800A01A8

Error in pptfigure (line 564)
metaWidth = get(pic,'Width');

Error while evaluating uipushtool ClickedCallback"

27 Feb 2013 Darik  
03 Oct 2012 Renwen Lin  
05 Sep 2012 Matt Caywood

Overall this function is good but is very finicky. It's the best way I've found to get vector graphics out of Matlab, but it's not for beginners.

My admiration to the author for digging into the swamp of Matlab graphics, which even Mathworks is afraid to touch.

05 Sep 2012 Matt Caywood

If my figure is wider than *exactly* 1253 pixels, pptfigure will not copy it to Powerpoint (2010) correctly -- it will leave a stray garbage "coded" axis to the upper left of the slide.

This axis is created by
line 561: pic = invoke(slide.Shapes,'PasteSpecial',3);

and supposed to be destroyed (but not fully destroyed) by line 601: invoke(pic,'Delete');

27 Jul 2012 Daniel  
27 Jul 2012 Daniel

Just got this and absolutely amazed. It makes the plots from Matlab look so clean in PowerPoint. An absolute Must!

31 May 2012 claire OLDFIELD

It works great, except it doesn't preserve the transparency setting of the "fill" on my graph. Any idea how I can add that?
Thanks!

18 May 2012 Daniel Helmick

Works great in most situations. I really love this.

Also doesn't capture the plot correctly if lines are turned off during the copying process.

04 May 2012 Joachim  
25 Apr 2012 Darren

This is a fantastic file. However, I run into trouble trying to export text with the sprintf function. It ends up omitting the text. Thoughts?

07 Feb 2012 Benjamin

As of Feb 2012, pptfigure does not seem to properly export colorbars to Power Point. I made two changes to the code to make colorbars work (at lines 874 & 1109):
@@ -874,6 +874,18 @@
if ~isempty(find(legends==objects(obj),1))
set(get(objects(obj),'children'),'visible','on');
end
+ if strcmp(get(objects(obj),'Tag'), 'TMW_COLORBAR')
+ % For colorbars, parent axes need to be visible.
+ set(get(objects(obj), 'parent'),'visible','on');
+ % Make colorbar ticks temporarily invisible by clearing their
+ % text, but keep colorbar axis labels in same positions.
+ ytick = get(get(objects(obj), 'parent'),'ytick');
+ cbar_lbl = findobj(objects, 'Type','text', ...
+ 'Parent',get(objects(obj),'Parent'));
+ cbar_lbl_pos = get(cbar_lbl,'Position');
+ set(get(objects(obj), 'parent'),'ytick',[]);
+ set(cbar_lbl,{'Position'},cbar_lbl_pos);
+ end
set(objects(find(invisible)),'visible','off'); %#ok<FNDSB>

% Set axis positions to original values
@@ -1109,6 +1121,10 @@
if strcmp(type,'text')
set(objects(obj),'interpreter',interpreter);
end
+ if strcmp(get(objects(obj),'Tag'), 'TMW_COLORBAR')
+ % Restore YTick values to colorbar axes
+ set(get(objects(obj), 'parent'),'ytick',ytick);
+ end
end
end

The problem is that the image containted within the colorbar axes does not display when its 'Visibile' property is set to 'on'.

02 Feb 2012 Guy

Similar to Hugh's problem, If I already have PowerPoint open, it works great. If not, if I try to use this from either the command line or the figure button I get the following error:

??? Invoke Error, Dispatch Exception:
Source: Microsoft Office PowerPoint 2007
Description: Application.ActiveWindow : Invalid request. There is no currently
active document window.
Help File:
Help Context ID: 0

Error in ==> pptfigure at 343
wind = get(ppt,'ActiveWindow');

??? Error while evaluating uipushtool ClickedCallback

28 Dec 2011 Hugh

Hi, I typed "pptfigure", nothing happended. What did I do wrong?

25 Oct 2011 Tim

Excellent program!

I initially had problems with the legend in the PowerPoint slide. For some reason if the symbol was a circle ('o') or square ('s'), it was removed. If I changed the symbols to something other than circles or squares, it seemed to be okay. As a temporary fix, I commented out line 939, and all symbols made it.

938 if isempty(deblank(txt)) returns 939 %invoke(pic.Item(c),'Delete');

If you have a better fix, please let me know.

Thanks!

06 Oct 2011 Sander Aerts

I have the same problem as Boris. When i run the following:
>> clear all, close all
>> [~]=peaks;view(2);
>> pptfigure(1);
??? Invoke Error, Dispatch Exception:
Source: Microsoft PowerPoint 2010
Description: ShapeRange.Item : Integer out of range. 2 is not in Index's valid range of 1 to 1.
Help File:
Help Context ID: 0

Error in ==> pptfigure at 926
invoke(pic.Item(2),'Delete');

Basically the same error but then with powerpoint 2010. It does however create a slide but the created object somehow appears to be totally blank.
If it worked properly I would certainly use this tool.

23 Sep 2011 Doug Harriman  
16 Sep 2011 Boris

I tried this with PowerPoint 2010 SP1 on Windows XP SP3, using Matlab 2010a. The button appears, and when you click it, it opens PowerPoint, but then just generates a blank slide... No errors are given but it appears not to work (unfortunately)... I was trying to export a mixed area and line plot.

08 Sep 2011 Yuri K

I was very excited about this function. But does it work with PowerPoint 2007? Not working for me. MATLAB 2011a.
pptfigure does not open figure and returns no error. If I create the figure myself then:
>> pptfigure(gcf)
??? Invoke Error, Dispatch Exception:
Source: Microsoft Office PowerPoint 2007
Description: ShapeRange.Item : Integer out of range. 2 is not in Index's valid range of 1 to 1.

26 Aug 2011 Federico Miorelli

Great idea and incredibly easy to use!
I have an issue with some types of plot though: for example if I plot any matrix with pcolor I get an error when exporting.

Thanks!

28 Jul 2011 Etienne

Hi Dmitriy

My axes title labels are duplicated several times. I checked in the original, but there is only one instance. Have you seen this problem before?

04 May 2011 Cristina

This exporter is awesome. You won't have to regenerate matlab figures to make them legible, rescale subplots, change distances between functions, change colors, font size, add or remove tick marks to the axes, remove parts of your plot that you don't want on your slides etc. It takes most of the pain out of working with matlab figures :) thank you :) :) :)

Updates
10 Feb 2011

Improved speed, better documentation, fixed TEX exporting bug, added some optional exporting properties.

10 Feb 2011

Corrected documentation/acknowledgement typos

11 Feb 2011

Fixed minor bug during scientific axis exporting

18 Feb 2011

- Added options for exporting figure/axis background colors - Added bitmap exporting option - Added image resolution properties - Added full support for TEX formatting - Corrected minor bugs

Contact us