OLE Objects and ActiveX Controls
OLE Objects and ActiveX Controls
Aspose.Words FOSS for .NET provides read access to embedded OLE objects and Forms 2.0 ActiveX controls through the OleFormat entry point and its related classes in Aspose.Words.Drawing and Aspose.Words.Drawing.Ole.
Accessing Embedded OLE Object Data
OleFormat is exposed by an embedded Shape and provides access to the raw data and metadata of the embedded object. SuggestedFileName and SuggestedExtension describe what the embedded object would be saved as, ProgId identifies the OLE server application that created it, and IsLink distinguishes a linked object (SourceFullName/SourceItem point to the external source) from a fully embedded one. GetOleEntry(oleEntryName) reads a specific named stream from the OLE compound file structure, GetRawData() returns the complete raw object data, and Save(fileName) / Save(stream) write the embedded object’s native data out to disk or a stream — useful for extracting the original embedded file (for example an embedded spreadsheet or presentation) without opening it in its native application. OlePackage, reached via OleFormat.OlePackage, exposes FileName and DisplayName for objects embedded as an OLE Package.
Working with Forms 2.0 ActiveX Controls
Where the embedded object is a Microsoft Forms 2.0 ActiveX control (checkboxes, text boxes, combo boxes, and similar interactive controls rather than embedded documents), OleFormat.OleControl returns an OleControl. Check its IsForms2OleControl property, and if true, cast it to Forms2OleControl (the abstract base class for all Forms 2.0 controls) to reach control-specific properties: Caption, Value, Enabled, Type (a Forms2OleControlType value — CheckBox, Textbox, ComboBox, OptionButton, ListBox, CommandButton, and others), plus visual properties ForeColor, BackColor, Width, and Height. Container controls such as frames expose their nested controls through ChildNodes, a Forms2OleControlCollection.
Tips and Best Practices
- Check
OleFormat.IsLinkbefore assuming embedded object data is present locally — linked objects reference an external file viaSourceFullNameinstead of embedding their content. - Use
SuggestedExtensiontogether withSave()to reconstruct a sensible output filename when extracting embedded objects in bulk. - Always check
OleControl.IsForms2OleControlbefore casting toForms2OleControl— not everyOleControlis a Forms 2.0 control. Forms2OleControlCollection.Countand enumeration viaGetEnumerator()let you walk nested controls inside a frame or multi-page container control.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
GetRawData() returns unexpected/empty data | Object is a link (IsLink == true), not embedded | Check IsLink first; resolve SourceFullName for linked objects |
InvalidCastException casting OleControl to Forms2OleControl | Control is not a Forms 2.0 control | Check IsForms2OleControl before casting |
GetOleEntry() returns null for a named stream | Stream name doesn’t exist in this object’s compound file structure | Enumerate the actual entry names rather than assuming a fixed name |
| Nested controls inside a frame not found | Only checked the top-level OleControl, not ChildNodes | Recurse into Forms2OleControl.ChildNodes for container controls |
FAQ
How do I extract an embedded Excel or PowerPoint object from a Word document?
Access the shape’s OleFormat, then call Save(fileName) or GetRawData() to retrieve the embedded object’s native bytes; use SuggestedExtension to name the output file appropriately.
What’s the difference between an embedded OLE object and a Forms 2.0 control?
An embedded OLE object (accessed via OleFormat directly) is typically another document (spreadsheet, presentation); a Forms 2.0 control (OleFormat.OleControl → Forms2OleControl) is an interactive UI element like a checkbox or text box.
How do I tell if an OLE object is linked rather than embedded?
Check OleFormat.IsLink — when true, SourceFullName and SourceItem describe the external source instead of the object carrying its own data.
Can I read the caption or value of a checkbox control?
Yes — cast the OleControl to Forms2OleControl (after confirming IsForms2OleControl) and read Caption and Value.
API Reference Summary
| Class / Method | Description |
|---|---|
OleFormat | Entry point for an embedded OLE object’s data and metadata |
OleFormat.GetRawData() | Retrieve the raw embedded object bytes |
OleFormat.Save() | Save the embedded object’s native data to a file or stream |
OlePackage | File name/display name for an OLE Package object |
OleControl | Base representation of an embedded ActiveX control |
Forms2OleControl | Microsoft Forms 2.0 control (checkbox, textbox, combo box, etc.) |
Forms2OleControlCollection | Collection of child Forms2OleControl nodes (e.g. inside a frame) |
Forms2OleControlType | Enum of Forms 2.0 control kinds |