Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
OLE stands for “Object Linking and Embedding”. This is the technology by which users can work with documents containing “objects” created or edited by third-party applications. That is, OLE allows an application to export these “objects” to another application for editing, and then import them back with some additional content.
In this article, we will talk about inserting an OLE object and setting its properties into a document.
If you want OLE Object, call the InsertOleObject method and pass it the ProgId explicitly with other parameters.
The following code example shows how to insert OLE Object into a document:
OLE package is a legacy and “undocumented” way to store embedded objects if an OLE handler is unknown.
Early Windows versions such as Windows 3.1, 95, and 98 had a Packager.exe application that could be used to embed any type of data into the document. This application is now excluded from Windows, but Microsoft Word and other applications still use it to embed data if the OLE handler is missing or unknown. The OlePackage class allows users to access the OLE Package properties.
The following code example shows how to set the file name, extension, and display name for OLE Package:
Users can access OLE object data using various properties and methods of the OleFormat class. For example, it is possible to get the OLE object raw data or the path and name of a source file for the linked OLE object.
The following code example shows how to get OLE Object raw data using the GetRawData method:
OLE objects can also be inserted into documents as images.
The following code example shows how to insert OLE Object as an icon. For this purpose, the DocumentBuilder class exposes the InsertOleObjectAsIcon method.
The following code example shows how to inserts an embedded OLE object as an icon from a stream into the document:
Online video can be inserted into Word document from the “Insert” > “Online Video” tab. You can insert an online video into a document at the current location by calling the InsertOnlineVideo method:
The DocumentBuilder class introduces four overloads of this method. The first one works with the most popular video resources and takes the URL of the video as a parameter. For example, the first overload supports simple insertion of online videos from YouTube and Vimeo resources.
The following code example shows how to insert an online video from Vimeo into a document:
The second overload works with all other video resources and takes embedded HTML code as a parameter. The HTML code for embedding a video may vary depending on the provider, so contact the respective provider for details.
The following code example shows how to insert an online video into a document using such HTML code:
Q: How do I insert an OLE object from a file stream in Java?
A: Use DocumentBuilder.insertOleObject(InputStream stream, String progId, boolean isLinked, InputStream iconStream). Provide the object’s ProgID (e.g., "Word.Document"), the data stream, and optionally an icon stream.
Q: How can I set a custom file name, extension, and display name for an OLE package?
A: Create an OlePackage instance, then call setFileName(), setExtension(), and setDisplayName() before inserting it with DocumentBuilder.insertOleObject.
Q: What is the way to retrieve the raw binary data of an embedded OLE object?
A: Obtain the OleFormat object from the OLE node (OleFormat ole = (OleFormat)node;) and call ole.getRawData() to get a byte array containing the original data.
Q: How can I insert an OLE object as an icon rather than as embedded content?
A: Use DocumentBuilder.insertOleObjectAsIcon(InputStream stream, String progId, String iconFileName, String iconDisplayName); this inserts the object and displays the specified icon image.
Q: How can I detect whether a document contains any OLE objects?
A: Iterate through the document’s OLE nodes:
NodeCollection oleNodes = doc.getChildNodes(NodeType.OBJECT, true);
for (Node node : oleNodes) {
if (node instanceof OleFormat) {
// OLE object found
}
}
If the collection is non‑empty, the document includes OLE objects.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.