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

Free Support Forum - aspose.com

Embedded object - aspose words

Dear Team,
How to find whether an image is excel embedded word document using aspose words…?
Is their any method to find it?
Thanks in advance…

@resh05

You can use Shape.OleFormat property to get access to the OLE data of a shape. For a shape that is not an OLE object or ActiveX control, returns null. The OleFormat.SuggestedExtension property is used to get the file extension suggested for the current embedded object if you want to save it into a file.

Following code example shows how to extract embedded OLE objects into files and shows how to check embedded Excel file.

Document doc = new Document(MyDir + "Shape.Ole.Spreadsheet.docm");

// The first shape will contain an OLE object
Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

// This object is a Microsoft Excel spreadsheet
OleFormat oleFormat = shape.OleFormat;
Assert.AreEqual("Excel.Sheet.12", oleFormat.ProgId);

// Our object is neither auto updating nor locked from updates
Assert.False(oleFormat.AutoUpdate);
Assert.AreEqual(false, oleFormat.IsLocked);

// If we want to extract the OLE object by saving it into our local file system, this property can tell us the relevant file extension
Assert.AreEqual(".xlsx", oleFormat.SuggestedExtension);

// We can save it via a stream
using (FileStream fs = new FileStream(ArtifactsDir + "OLE spreadsheet extracted via stream" + oleFormat.SuggestedExtension, FileMode.Create))
{
    oleFormat.Save(fs);
}

// We can also save it directly to a file
oleFormat.Save(MyDir + "OLE spreadsheet saved directly" + oleFormat.SuggestedExtension);

Hi @tahir.manzoor
Can i get the code in java…
Thanks…

@resh05

Please use the following code example to check the first Shape of document either it is Excel embedded object or not.

Document doc = new Document(MyDir + "input.docx");

// The first shape will contain an OLE object
Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true);

// This object is a Microsoft Excel spreadsheet
OleFormat oleFormat = shape.getOleFormat();
if(oleFormat.getProgId() == "Excel.Sheet.12")
{
    //Your code...
}

3 posts were split to a new topic: java.lang.NullPointerException is thrown by getOleFormat