Skip to main content

GetAllOleObjects

Returns a collection of OLE objects from the document content.

Inherited from ApiDocumentContent.GetAllOleObjects.

Example

Retrieve all OLE objects embedded in document content in a document.

// How do I access every OLE object inside a content container in a document?

// Read the application ID of the first OLE object and print it as a paragraph in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
let fill = Api.CreateSolidFill(Api.RGB(255, 111, 61));
let stroke = Api.CreateStroke(0, Api.CreateNoFill());
let shape = Api.CreateShape("rect", 100 * 36000, 100 * 36000, fill, stroke);
paragraph.AddDrawing(shape);
let oleObject = Api.CreateOleObject(
'https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png',
150 * 36000, 150 * 36000,
'https://youtu.be/SKGz4pmnpgY',
'asc.{38E022EA-AD92-45FC-B22B-49DF39746DB4}'
);
paragraph = Api.CreateParagraph();
paragraph.AddDrawing(oleObject);
let docContent = shape.GetDocContent();
docContent.AddElement(0, paragraph);
let oleObjects = docContent.GetAllOleObjects();
let appId = oleObjects[0].GetApplicationId();
paragraph = Api.CreateParagraph();
paragraph.AddText('The application ID for the current OLE object: ' + appId);
doc.Push(paragraph);