Click here to Skip to main content
12,397,805 members (53,050 online)
Click here to Skip to main content
Add your own
alternative version

Stats

71.5K views
4.8K downloads
36 bookmarked
Posted

Create a PowerPoint presentation using a template

, 10 Nov 2006
Rate this:
Please Sign up or sign in to vote.
Create a PowerPoint presentation using a template using the Office 2007 OpenXML format.

Sample Image

Introduction

In this article, I am trying to explain the PowerPoint 2007 file format and its structure by showing how to create a presentation using a template. This is a very useful example and can be used for various purposes. In this example, I am creating slides as per the user input for text and images. The class presentation in the code is designed in a way that anyone can automate the process of generating a presentation by feeding input from any source.

Background

Office 2007 has introduced a new file format called OpenXML. All the data/setting/metadata is stored in an XML file. First, quickly create a Word/Excel/PowerPoint file and save it. Now, close the application and rename the file with the extension .zip and open the file. You can see that all the .xml files are packed in there. Microsoft has released the September CTP for .NET Framework 3.0. It has an assembly called Windowbase.dll that has the namespace System.IO.Packaging that supports the Open Office 2007 package file to perform operations like adding/deleting parts and media. You can download it from here. I have used this namespace to work with this example. For further information about Office 2007 OpenXML file format, please read this article. You can get other resources from the online MSDN.

Using the code

In the code, I have written a class presentation that you can find in Presentation.cs. This class uses the System.IO.Packaging namespace. I have the template1.pptx file that you can find in the debug\bin\Template\ folder. I kept the file there just for ease of work. This program creates a copy of the file at the location input by the user (the program asks for the location on hitting the Create presentation button on the main form). Then, for each slide, it creates a copy of slide1.xml and gives it a name in sequence, like slide2.xml etc. Then, this program finds the node where it stores the text and replaces with the text that the user has keyed in, and then adds the image to the package and creates a relationship with the recently created slide(n).xml. It creates an entry of the created slide in presentation.xml and it also creates the relationship with slidelayout(n).xml. At the end, we save the package. The package class has a Save method to compress back the file, and that is it.

//open the package
package = Package.Open(filename, 
                       FileMode.Open, 
                       FileAccess.ReadWrite);

Points of Interest

This can be your first example to learn about the PowerPoint file format. If you understand the file format very well, you can change this example to meet your needs.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

sharadbajaj
Web Developer
United States United States
.Net System Designer working in USA with IT company since Jan-2005. I am having experience in Development of office application,Database application ,Java Application, and Banking Solutions.
I am having total 7.5 years of experience in IT. I have done various project for Wireless,Mobile tech.

You may also be interested in...

Comments and Discussions

 
QuestionIs it required to install ms office in server side Pin
febin sarafras16-Oct-14 20:35
memberfebin sarafras16-Oct-14 20:35 
QuestionHow can i delete a slide using the same code style Pin
Omda24069024-Apr-14 8:34
memberOmda24069024-Apr-14 8:34 
QuestionMessage Automatically Removed Pin
21-Oct-13 21:59
memberJamie Calops21-Oct-13 21:59 
SuggestionCorrection Pin
Member 918313522-Aug-12 19:01
memberMember 918313522-Aug-12 19:01 
QuestionDo other image files work? Pin
Member 79783461-Apr-12 6:00
memberMember 79783461-Apr-12 6:00 
QuestionIs it possible in server side? Pin
winsrividhya11-May-10 4:07
memberwinsrividhya11-May-10 4:07 
AnswerRe: Is it possible in server side? Pin
yusufelik11-Jan-12 3:26
memberyusufelik11-Jan-12 3:26 
QuestionPowerpoint in serverside Pin
ummu 27-Mar-10 19:45
memberummu 27-Mar-10 19:45 
GeneralIs it posible to extract images,cliparts and vidoes from PPTX file Pin
bloremohan2-Dec-08 9:03
memberbloremohan2-Dec-08 9:03 
GeneralRe: Is it posible to extract images,cliparts and vidoes from PPTX file Pin
yusufelik11-Jan-12 3:25
memberyusufelik11-Jan-12 3:25 
GeneralDynamic XML template-based PowerPointCreator in C# Pin
Elmue29-Aug-08 13:05
memberElmue29-Aug-08 13:05 
GeneralDoesn't work Pin
JSBBS29-Jun-08 18:57
memberJSBBS29-Jun-08 18:57 
GeneralDifferent Image and media at same presentation .. Pin
MrHoSo14-Mar-08 6:57
memberMrHoSo14-Mar-08 6:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 10 Nov 2006
Article Copyright 2006 by sharadbajaj
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid