HOW TO GET Word embedded object


#1

word A use word B ,HOW TO GET Word embedded object


#2

@echozhum

Following code example shows how to extract embedded OLE objects into files.

Document doc = new Document("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.getOleFormat();
Assert.assertEquals(oleFormat.getProgId(), "Excel.Sheet.12");

// Our object is neither auto updating nor locked from updates
Assert.assertFalse(oleFormat.getAutoUpdate());
Assert.assertEquals(oleFormat.isLocked(), false);

// 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.assertEquals(oleFormat.getSuggestedExtension(), ".xlsx");

// We can save it via a stream
OutputStream stream = new FileOutputStream("OLE spreadsheet extracted via stream" + oleFormat.getSuggestedExtension());
oleFormat.save(stream);

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