Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some techniques for generating PowerPoint presentations without using Office Automation?

While it is possible to generate PowerPoint presentations automatically using Office Automation, this is not recommended for use on a server. How can you go about generating a PowerPoint presentation without using Office Automation?

like image 527
rjzii Avatar asked May 05 '09 14:05

rjzii


1 Answers

Another option that didn't get mentioned, which was the route we ultimately took, is to make use of the Open XML file formats that are supported naively in Office 2007 and in Office XP via a compatibility pack. Using the Open XML SDK 1.0 getting something working turned out to be surprisingly straightforward.

First, a generic template file was prepared with tokens put in place of the content that would need to be replaced. Next, a reference to DocumentFormat.OpenXml needs to be added to the project. The code itself will reference the DocumentFormat.OpenXml and DocumentFormat.OpenXml.Packaging namespaces. Finally, the code to loop through the slides looks like the following:

// Open the presentation
PresentationDocument presentation = PresentationDocument.Open(fileName, true);
// Loop through all of the slides in the presentation
foreach (SlidePart slide in presentation.PresentationPart.SlideParts)
{
    // Read the XML out of the slide
    XmlDocument xml = new XmlDocument();
    xml.Load(slide.GetStream());

    // TODO: Your XML manipulation code here

    // Save the updated slide
    xml.Save(slide.GetStream());
}
// Save the updated presentation
presentation.Close();
like image 124
rjzii Avatar answered Nov 15 '22 05:11

rjzii