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

关于自动更新 OLE 对象

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

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

安装此类插件后,只需将 Auto_Open() 宏(在“事件生成器”中为 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;
}
}
}