使用 MS PowerPoint 插件自动更新 OLE 对象

关于自动更新 OLE 对象

Aspose.Slides 的客户常常问的一个问题是如何创建或更改可编辑图表或其他 OLE 对象,并在打开演示文稿时自动更新它们。不幸的是,PowerPoint 不支持 Excel 和 Word 中可用的任何自动宏。唯一可用的是 Auto_Open 和 Auto_Close 宏。然而,这些宏只有在插件中才能自动运行。这个简短的技术小贴士展示了如何实现这一点。

首先,有几款免费的插件可以为 PowerPoint 添加 Auto_Open 宏功能,例如 AutoEvents Add-inEvent Generator

安装此类插件后,只需将 Auto_Open() 宏(在“Event Generator”中为 OnPresentationOpen())添加到您的模板演示文稿中,如下所示:

Shape oShape;
Slide oSlide;
// Loop through each slide in the presentation.
for (var oSlide : ActivePresentation.Slides) {
// Loop through all the shapes on the current slide.
for (var oShape : oSlide.Shapes) {
// Check whether the shape is an OLE object.
if ((oShape.Type == msoEmbeddedOLEObject)) {
// Found an OLE object; obtain object reference, and then update.
oObject = oShape.OLEFormat.Object;
oObject.Application.Update();
// Now, quit out of the OLE server program. This frees
// memory, and prevents any problems. Also, set oObject equal
// to Nothing to release the object.
oObject.Application.Quit();
oObject = null;
}
}
}