views:

946

answers:

3

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?

A: 

You could write some server-side code that uses a library that can generate PowerPoint format documents. For example, in Java you can use Apache POI-HSLF to generating PPT files programmatically.

Depending on what you need to do, it may be less work to start with a 'template' PPT file, and modify it programmatically to insert or edit content.

Peter Hilton
A: 

If your server-side technology is ASP.NET, you could use Aspose.Slides. It's quite powerful and works well, though it might not be a cost-effective solution, depending on what you want to do.

Mun
+3  A: 

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();
Rob