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?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With