在不使用Office Automation的情况下生成PowerPoint演示文稿的一些技巧是什么?

时间:2009-05-05 14:53:08

标签: .net ms-office powerpoint openxml

虽然可以generate PowerPoint presentations automatically using Office Automation,但这是not recommended for use on a server。如何在不使用Office Automation的情况下生成PowerPoint演示文稿?

3 个答案:

答案 0 :(得分:5)

另一个未被提及的选项,即我们最终采用的路线,是利用Open XML文件格式在Office 2007和Office XP中通过{{3}天真支持}。使用compatibility pack获得的工作结果令人惊讶地直截了当。

首先,准备了一个通用模板文件,其中代币代替了需要替换的内容。接下来,需要将对DocumentFormat.OpenXml的引用添加到项目中。代码本身将引用DocumentFormat.OpenXml和DocumentFormat.OpenXml.Packaging命名空间。最后,循环播放幻灯片的代码如下所示:

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

答案 1 :(得分:0)

您可以编写一些使用可生成PowerPoint格式文档的库的服务器端代码。例如,在Java中,您可以使用Apache POI-HSLF以编程方式生成PPT文件。

根据您的需要,开始使用“模板”PPT文件并以编程方式修改以插入或编辑内容可能不那么重要。

答案 2 :(得分:0)

如果您的服务器端技术是ASP.NET,则可以使用Aspose.Slides。它非常强大并且运行良好,但它可能不是一个经济有效的解决方案,具体取决于您想要做什么。