exportToPPTX allows user to create PowerPoint 2007+ (PPTX) files without using COM-objects automation (or PowerPoint application itself). exportToPPTX writes PPTX files natively.
Note about PowerPoint 2003 and older: To open these PPTX files in older PowerPoint software you will need to get a free office compatibility pack from Microsoft: http://www.microsoft.com/en-us/download/details.aspx?id=3
Basic command syntax:
List of available commands:
* new - start new file
* open - open (to append to) existing file or template
* addslide - add new slide
* addnote - add slide notation
* addpicture - add image (figure handle, CDATA, image filename) to current slide
* addtext - add textbox to current slide
* addshape - add line or patch to the current slide
* addtable - add table to the current slide
* save - save file
* close - close (clear temporary file)
* query - get information about current status
More elaborate examples are included in examples_exportToPPTX.m and examples2_exportToPPTX.m files.
Up-to-date version, a more detailed help, bugs/issues tracking can all be found here: https://github.com/stefslon/exportToPPTX
Thanks for the response.
I tried the commands below, but get an error below because I need to have an objID:
Reference to non-existent field 'objId'.
Error in exportToPPTX>addPicture (line 1978)
PPTXInfo.Slide(PPTXInfo.currentSlide).objId = PPTXInfo.Slide(PPTXInfo.currentSlide).objId+1;
the simplest way to add a figure to the slide is to grab figure handle when creating your figure and then pass it on to addpicture command like so:
figH = figure(); % grab figure handle
plot(rand(10)); % add something to the plot
exportToPPTX('addpicture',figH); % add figure to the slide
For other examples see examples_exportToPPTX.m file provided with exportToPPTX.
This is a simple question using the exportToPPTX:
I do not understand how to use the addpicture or add figure input. I have a figure that I want to add to the slide.
I am sure this is a simple command.
@Tobin, yes, see examples2_exportToPPTX.m example file. It opens up provided Parallax.pptx template, lists all available template layouts and adds some slides using different layouts.
This is a fantastic tool.
Is there a way to specify the master slide or theme when creating a new PPT?
Or is there a way to specify the theme when adding a slide?
i want to express again my sincere thanks for your great tool.
one suggestion for addition that would be great:
could you add option of Hyperlinking text and objects?
i see you have hyperlink to another slide by 'OnClick' property to the textbox, but-
i find it very useful to add hyperlink to figures (or other source data), so i can link each figure in the pptx to its origin Matlab fig file, in case a data exploration or figure modification is needed.
for example, enabling code like:
which by click on picture, will execute like any pptx hyperlink.
this general method will work for any type of placeholder, and any type of linked file.
hope you will find it appropriate suggestion.
Good job man, it worked for me ! Without the sound actually, but still.
This is a terrific tool that I've been using a Matlab app that I built for my team. Recently, it became easier to distribute as an *.exe rather than a toolbox, but...
When using in a deployed (*.exe) mode, the exportToPPTX('save',filename) command will fail because the |writePPTX| subfunction does not use the 'f' overwrite flag in the |movefile| call.
Perhaps you could include revision in your next update?
Thanks for a great tool.
@Jakob, I will look into it. Another option is to use cell arrays when specifying text for the textbox. Each cell in the cell array will become its own line. You can see an example of this in examples_exportToPPTX.m.
thank you for your great tool.
I have a problem, that line breaks with '\n' don´t work when generating an text with 'addtext'.
The error seems to be in line 818 - function: addTxBodyNode
paraText = regexp(inputText,'n','split');
The splitting doesn´t work with '\n'. I tried a bit and found a workaround:
paraText = strsplit(inputText, '§'); % <-- Replace line 818 with this.
I now use '§' as line breaking delimeter.
Maybe you find a nice way to make '\n' work.
Greetings from Germany.
Works great, but how to make a list in a textbox? I can't figure out, how to add more lines into a singe textbox..
Stefan, thanks for the quick reply! And I did see this when I was changing the dimension parameters, thank you.
@TNH, when starting new PPTX file, use the following command exportToPPTX('new','Dimensions',[10 5.63]) or whatever your desires presentation size is. The numbers are in inches. An example of this command is in examples_exportToPPTX.m file.
How do you adjust the slide size (or really the ratio from 16:9 to 4:3)?
thanks, Stefan ! very useful. it did great job for me, and I'm truly grateful for that.
* one important comment:
trying to create placeholders in Office2016 resulted with defected file that after being auto-repaired by PP, and severe positioning errors. reason found: somehow, new placeholder positions have 2 extra 'NaN's, in addition to the 4 digits position.
inserting the following lines on line#2148 did the job for me:
if length(frameDimensions)==6 % case where template created by new template format
you might want to update your code (or find better fix).
regards, and thanks again!
Very, very useful. Easy to use and saves a lot of time by automating report preparation. Thanks!
Great package, really streamlines reporting.
One problem I came across recently in addressing Placeholders out of order. I have a slideshow with 10 pictures per slide, I'm loading images in in order, left to right, top to bottom. I have found that in order to address 'Picture Placeholder 1' it needs to be the first in the list when I call exportToPPTX('query'). Otherwise I get an error message saying there are too many input args. I guess the work around will be to make sure Placeholder 1 is first in the list (initially, powerpoint sent the placeholders in a strange order, 7, 8 9 10, 1 2 etc). Anyway, thought it would be useful to pass this on.
Thanks for writing such a useful set of functions!
It seems really good to use this code on both Linux and Windows because most of the example about this using COM-Server on Windows but nothing shows for Linux.
But I have a small problem with it. When I ran the example codes the .pptx files are generated but PowerPoint gives an error like these "Sorry, Powerpoint can't read the ..... .pptx file" and also I cannot delete these files if I am not on system admin account.
Could you please help me about this?
Hello, not sure if you are still monitoring this post. BUT I noticed that in September 2013 you tried to fix the PPT 2010 corruption bug? I don't think it was successfully fixed. Your function works great for me on PPT 2013, but will not work on a coworkers PPT 2010 Still.
Very Useful tool. However the addslide feature does not keep properties like footers and page numbers embedded in the template. Any workaround on how I can fix that?
No i am sorry, it does seem to be working in compiled version as well.
Very Well written function. Great work, adds tremendous value. I have developed a matlab exe, I want to add a function to generate a report in ppt and this allows me to do everything i had imagined.
- Text can be made click-able with 'OnClick' parameter, however currently it only links to other slides (no hyperlinks)
- Tables can be controlled with the same set of parameters as textboxes, so you can use 'Position' parameter to specify the placement of the table. Position needs to be provided as a four element vector: x, y, width, height (in inches).
Excellent script! However, I have two questions:
* Is there to include hyperlinks in the text strings added to the Powerpoint?
* Is there any command to compress/minimize the sizes of the heights in a table? Currently it seems that all sides in the table are equally long
I'm seeing an error when using 'exportToPPTX('addnote',...'. PPTX file is created, but PPT gives 'Microsoft PowerPoint has stopped working' error.
Occurs with examples2_exportToPPTX.m & disappears when I comment out the 'addnote' calls. Win 7 64 bit, Matlab R2015b, Office 2013.
I am trying to copy double type values with a negative sign in front eg(-2.456e-6) converted to string (case1) and also in the form of tables(case2) into a ppt in the form of textbox or tables. The data with negative sign becomes a bullet when it appears in the .ppt file . Please help with the solution for the above issue.!
Thank you so much in advance!
Having issues with eps and pdf files importing into ppt with this tool. Jpg's work fine but when adding a figure via filename that was saved as an eps the subsequent powerpoint says the image is corrupted (it's not). With pdf's it says it can't determine the file format. Can you add support for all the methods that matlab's saveas supports?
I'm having some trouble producing a slide using 'addtext' where the text is a negative number. Is there a way to start a line using addtext with a minus sign and not have ExportToPPTX automatically trigger it as a bullet point?
Stefan - Thanks very much for this excellent tool. The addition of support for ppt templates moves the utility to an entirely new level. I use this all the time and have found it to work flawlessly.
Phillip, you are correct, there is no way to delete or overwrite a slide. The idea was that you are generating a presentation from scratch so you don't need to edit it in MatLab.
This is a great tool, but it's missing a feature that I would find very useful - the ability to overwrite or delete a slide. Is there a work-around or feature that I'm missing?
Hi Stefan, I suppose to pass in a handle. To be sure, here is my procedure: I have written a script that opens the desired figure, saves it as a vector file (.emf) and then it calls exportToPPTX function.
Matteo, do you pass in a path to the saved file into exportToPPTX? Or do you pass in a handle to the figure?
Hi Stefan! Thank you for the fantastic tool! I'm using it for 3 months and it is very useful. Unfortunately, in recent days I have encountered some problems (I don't know the origin, they're probably linked to Windows updates).
Solitally I save a fullscreen picture, and then I launch the function. But actually on the PPT slide I see only a part of the figure (more or less one fourth of the complete figure).
Could you help me?
Thank you in advance
P.S.: I work with Windows 7 Professional SP1, Matlab2014b and PowerPoint2013
FF, run the examples_exportToPPTX script to see if you can generate an example.pptx file. Version of PPT installed should not matter, because this tool doesn't use PowerPoint to create slides.
I can't make it work on MAC OS X Mavericks (with ppt for mac 2011). I don't get an error message when executing commands (e.g. exportToPPTX('add slide')), but nothing happens. Any suggestions?
Great! All works perfectly!
Really very very nice. However the default size appears to be 10x8 and not 10x7.5 and it is impossible to create any other size. It looks like the ('new',[11.7 8.27]) is ignored (MATLAB 2014b, MS Office 2013)
Thanks a lot. Very nicely put together.
Update for 2014B: make the changes below to
function PPTXInfo = addPicture(PPTXInfo,imgData,varargin)
I have NOT check all variations of exportToPPTX in 2014B
My earlier problems, where my own errors in having a mismatch between 'new' at start of my scrip and 'save' at the end.
Stefan. Fantastic application!! It has saved me a great deal of effort in making changes to my COM application. I had to update when it went from 2007 to 2010 and now I am faced once again with updating. You have saved me that work.
I noticed that if I create a power point, save and close it, then re-open I have problems adding a picture or notes if the original power point didn't have pictures or notes in it.
I think the problem is related to creating directories.
Thank you for the great application.
Thanks a million, you saved me a lot of time and effort.
HI Stefan. This is great. Thank you
I do have one problem thou. I can load an existing pptx. But how do I change to an current slide and add new text/etc to it. Currently you only seem to add anew slide onto the end and them add new text etc to that one. Thank you
This is a very nice script and I have been using it a lot and building more complex code around it. thanks for your work.
I do have some questions:
Is there a way to select custom themes? My company has its own theme it uses for presentations. Thanks
Norman, font type is currently not supported. I will add it when I get some free time. exportToPPTX does not handle templates at this time, so you can't select slide layout. I am slowly working on adding a this feature though.
Is there a way to change the Font Type?
Also is the a way when adding a new slide you tell it what layout to use?
Thank you in advance.
Hans, exportToPPTX will not be able to add a movie to the slide at this time. But it won't be too hard to add this feature. So I will add it to the list of things to do...
Say that I make an animation in MATLAB using movie().
Can I use exportToPPTX to export it to ppt?
Excellent supplementary tool. Easy to integrate into existing code and simplify report generation.
wei, you can use any format you want as long as PowerPoint supports it. It supports PNG, JPG, GIF, BMP, TIF and many others raster image formats. EMF format is an example of vector file formats. Another example would be EPS. Using vector format has an advantage of being able to zoom in as much as you want without losing details. However with complicated figures vector format very quickly becomes large in size. I included EMF in the examples_exportToPPTX script just to show that exportToPPTX supports vector formats.
Nice script, but Im keep on getting the error message:
Error using copyfile
The system cannot find the path specified.
-> 881 copyfile(imgData,imagePath);
I used: addPicture(PPTXInfo,'myPic.bmp',varargin)
Any solution pls?
Very nice work, However, saveas(...,emf) in examples_exportToPPTX could not properly work in MAC OS, Could you change this to another formate, such as jpeg or png.
What a useful tool!
Very nice, Stefan!
A couple of requests.
1. I would like to be able to apply existing templates to the PPTX.
2. It would be nice to apply a standard layout, such as title slide, agenda slide, title and content, title and two contents, etc.
3. Related to #2, once I apply a standard layout, I would like to put in text to the standard text box, instead of adding a new text box.
It works well with office 2013. Thanks.
Lube F, I have just submitted an updated version that seems to work with Office 2010. I say "seems" because I was only able to test it with PowerPoint 2010 Viewer. I do not have an access to a full-blown Office 2010 at the moment. Please let me know if you still see the issue. Updated version should appear on here in a few days, or you can get it now from GitHub. Thanks!
aahhh what happened to my first comment?!!
what i said was:
fantastic submission, but i've run into the 2010 corruption bug you mention here:
and then i went off for a while to try to work out the problem, and the only thing i found to work was...
ok well a crappy workaround is to open with powerpoint 2007 viewer then use a pdf printer to create a pdf, and then use a pdf to pptx converter. it does the job but obviously it's not ideal!
perhaps you could also workaround with openoffice?
i have found 2 problems:
1. if you create a new PPTX without specifying the dimensions, (PPTX default = 10" x 7.5")
then if you want to save (append) to the same PPT file the 2nd time, it throws an error @ about line 402:
about "createdDate" does not exist:
PPTXInfo = rmfield(PPTXInfo, ....)
it appears that createdDate is assigned only if the dimensions are explicitly given.
so right now, i always give dimensions.
2. the axis scale does not seem to stick.
it always appears to be auto-scale. so my workaround is always use "saveas" in a temporary png file then add it in PPT/
thanks Stefan for such a speedy response
works beautifully, exactly what i need.
Thanks, p kung. Latest version is up, it should now work with multiple images properly. Let me know if you see any other bugs.
Jonathan is right,
i also can't create 4 different plots on the same figure. they're all identical.
in your example, you plot earth 4 times & put them in 2x2 plots on a slide.
now i want to plot 4 different plots/images & put them in 2x2 plots on one slide.
somehow, the 2x2 plots are of the same image (last plot) 4 times.
if you could kindly fix this bug, i'd give it 5 stars.
In terms of capturing screen rather than figures, this is a known getframe limitation. See MathWorks' article on a potential workaround: http://www.mathworks.com/support/solutions/en/data/1-3NMHJ5/ You can use hardcopy method to get figure/axis CDATA and then just pass that to exportToPPTX. An example of passing CDATA to exportToPPTX is available in examples_exportToPPTX.m
To save figures in another file format use MatLab's imwrite function to write to a temporary file and then call exportToPPTX with that filename. For example:
img = getframe(gcf);
exportToPPTX('addpicture','temp.jpg','Position',[6 3.5 3 2]);
In terms of plans for notes support, I was hoping to add it at some point.
With MATLAB running in the background--and exportToPPTX being called from within a nested loop--I was using Firefox in the foreground. When the MATLAB simulation complete, I noticed screen shots of my web browsing session appearing in the PPTX files produced by exportToPPTX. Furthermore, it would also appear that if the PC is "locked" during a simulation, then the exportToPPTX pastes completely black figures into the PPTX file.
Apart from neither locking my PC nor using it for anything else during a simulation, is there an alternative way of ensuring that the figures are not corrupted?
Thanks for this excellent function which provides massive speed improvements compared to the COM method.
When using the function within a loop, I found that I had to clear PPTXInfo to avoid an error that occurred the second time the function was called. On line 394, I replaced "PPTXInfo.fileOpen = false;" with "clear PPTXInfo".
A couple of questions:
Figures are pasted into the PPTX as PNG. Would it possible to paste using a different graphics format?
Do you have plans to allow slide notes to be added?
Jonathan, I tested it with four images (in the examples_exportToPPTX.m script) and it worked fine. Can you please provide more details about this bug?
This is great.
However, I did encounter a bug. It seems as though you can only have unique image per slide. This is quite limiting. If you can fix this bug, I'd gladly change my rating to 5 stars
Thanks for the suggestion, Darik. I have added this and a few other options to the latest version.
Nice work. This is definitely a lot faster than the alternative COM implementations. I suppose the trade-off is that you can't export to a file if it's already open in Powerpoint.
I'd suggest you split the addpicture method up into 'addfigure' and 'addimage'. The latter could accept a png file as input instead of a figure handle, which would make your function a lot more compatible with all the other exporting functions on the FEX, such as export_fig.
Add support for PowerPoint templates, add 'addtable' functionality, fix tabbing in markdown
Linked to GitHub version
Fixed (hopefully) Office 2010 compatibility issue
- Add "BackgroundColor" option to slides
added ability to add notes to slides, plus fixed a number of bugs
Fixed bug that caused multiple images to override each other on a single slide.
* Throw a more descriptive error if there is one when writing PPTX file