MS PowerPoint アドインを使用して OLE オブジェクトを自動的に更新
OLE オブジェクトを自動的に更新することについて
Aspose.Slides の顧客からよく寄せられる質問の一つは、編集可能なチャートやその他の OLE オブジェクトを作成または変更し、それらがプレゼンテーションを開く際に自動的に更新されるようにする方法です。残念ながら、PowerPoint は Excel や Word で利用可能な自動マクロをサポートしていません。利用可能なのは、Auto_Open と Auto_Close マクロのみです。しかし、それらはアドインからのみ自動的に実行されます。この短い技術的ヒントでは、その方法を示します。
まず、PowerPoint に Auto_Open マクロ機能を追加するいくつかのフリーウェアアドインが利用可能です。例えば、AutoEvents Add-in および Event 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; | |
} | |
} | |
} |