Skip to content

Instantly share code, notes, and snippets.

@ognjenm
Created December 30, 2018 12:46
Show Gist options
  • Save ognjenm/0e772d584ac37f68a1cfc5f02010c9fc to your computer and use it in GitHub Desktop.
Save ognjenm/0e772d584ac37f68a1cfc5f02010c9fc to your computer and use it in GitHub Desktop.
get Attachments from word document
Document doc = new Document(getMyDir() + “sample2.doc”);
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
for (Shape shape : (Iterable) shapes)
{
if (shape.getOleFormat() != null)
{
if (!shape.getOleFormat().isLink())
{
if (shape.getOleFormat().getProgId().equals(“Word.Document.12”))
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
shape.getOleFormat().save(baos);
InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
Document newDoc = new Document(inputStream);
doc.appendDocument(newDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment