How extract OLE object

Technical support for Spire.Doc

Moderator: iceblue support

How extract OLE object

Postby docwhosv » Sun Jan 30, 2011 4:04 pm

Hi, I have tons of word document with OLE object, someone is PDF and others are simple images.
Is there a way to extract OLE from documents and save in a path?
I see in your example and made some changes but ... I ask you HELP.

Dim document As New Document("Sample.doc")
3: Dim index As Integer = 0
5: 'Create a new queue.
6: Dim containers As New Queue(Of ICompositeObject)()
8: 'Put the document objects in the queue.
9: containers.Enqueue(document)
10: While (containers.Count > 0)
11: Dim container As ICompositeObject = containers.Dequeue()
12: Dim docObjects As DocumentObjectCollection = container.ChildObjects
13: For Each docObject As DocumentObject In docObjects
15: 'Judge the object type.
16: If (docObject.DocumentObjectType = DocumentObjectType.Picture) Then
17: Dim picture As DocOleObject = docObject
19: 'Name the image.
20: Dim imageName As String = String.Format("OLE{0}.pdf", index) 'I know this is a PDF
22: 'Find type
23: Dim ll As String = picture.ObjectType.ToString()
'Find storage name
ll = picture.OleStorageName.ToString
'Find packagefilename (if it's a package)
ll = picture.PackageFileName.ToString


24: index = index + 1
25: Else
26: If TypeOf docObject Is ICompositeObject Then
27: containers.Enqueue(TryCast(docObject, ICompositeObject))
28: End If
29: End If
30: Next
31: End While
Posts: 2
Joined: Thu Aug 05, 2010 9:49 am

Re: How extract OLE object

Postby » Mon Jan 31, 2011 5:46 am

Dear Flavio Balbo,

Thanks for your inquiry.
The DocumentObjectType of embedded OLE object is OleObject, so you could collect all OLE objects as:
Code: Select all
Document document = new Document(@"..\..\01-test.doc");

//document elements, each of them has child elements
Queue<ICompositeObject> nodes = new Queue<ICompositeObject>();

//embedded objects list.
IList<DocOleObject> oleObjects = new List<DocOleObject>();

while (nodes.Count > 0)
    ICompositeObject node = nodes.Dequeue();
    foreach (IDocumentObject child in node.ChildObjects)
        if (child is ICompositeObject)
            nodes.Enqueue(child as ICompositeObject);
        else if (child.DocumentObjectType == DocumentObjectType.OleObject)
            DocOleObject oleObject = child as DocOleObject;

The NativeData property of DocOleObject represents the data of the OLE object, you could save it to a file as:
Code: Select all
File.WriteAllBytes(fileName, oleObject.NativeData);

A full demo is attached, please check out. is for C# and is for VB.NET
You do not have the required permissions to view the files attached to this post.
Technical Support / Developer,
e-iceblue Support Team
User avatar
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Return to Spire.Doc

Who is online

Users browsing this forum: No registered users and 0 guests