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.
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.
package = Package.Open(filename,
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.
.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.