We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Identifying OLE Objects in Word Documents with Aspose.Words for .Net

Good afternoon,

I was wondering if / how I could find out whether a given .doc(x) file contains OLE Objects (such as an Excel Work Sheet)… and if so, how many.

What I tried is iterating over a Document’s child nodes (Shapes actually) via document.GetChildNodes(NodeType.Shape, true) and then simply check what shape.ShapeTypes are returned.

Strangely, even though I created a blank word document with exactly one Excel worksheet object in it… i get just one Shape of type ‘MinValue’… I’d have suspect to get one with OleObject (or maybe OleControl) … but no. So I assume I must be doing something wrong… but I wonder what?

Does anyone have / know how to iterate over / identify Ole Objects of a document (i.e. over the one in the attached sample .docx with, as mentioned, one Excel Worksheet)?


Hi there,

Thanks for your inquiry. Please check following sample code to extract OLE Objects from Word documents. You can check SuggestedExtension property to check OLE Object type. Hopefully it will help you to accomplish the task.

Document doc = new Document("Sample_File_2.docx");
int i = 0;
// Get collection of shapes
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
Console.Out.WriteLine("No. of Shapes:" + shapes.Count);
// Loop through all shapes
foreach (Aspose.Words.Drawing.Shape shape in shapes)
    if (shape.OleFormat != null)
        shape.OleFormat.Save(String.Format("E:\\Data\\out_{0}.{1}", i++, shape.OleFormat.SuggestedExtension));

Best Regards,

Thanks for the quick reply! I’ll give that a try… the thing that is a bit confusing is that ShapeType.OleObject is equal / identical to ShapeType.MinValue … and I grouped the Shape instances by their .ShapeType properties… therefore the OleObject ones ended up being grouped into the .MinValue ones.

Is that on purpose or is that a bug…? I’d expect the different ShapeType enums to be unique and not overlap and apparently all other ShapeTypes are indeed unique… only .MinValue and .OleObject have both an int value of -2.


Hi Jorg,

Thanks for your feedback. We have logged a ticket WORDSNET-15270 in our issue tracking system to investigate the value overlapping issue of ShapeType Enumeration members. We will keep you updated about the issue resolution progress within this forum thread.

Best Regards,

Great, thanks!

Hi Jorg,

Thanks for your patience. Please note it is not a bug it is expected behavior. MinValue and OleObject are same. All shapes with ShapeType.MinValue are OleObjects. Upon grouping shapes by shape type you can consider MinValue=OleObject.

Please feel free to contact us for any further assistance.

Best Regards,

Great - thanks for the clarification!