Created
December 30, 2018 12:46
-
-
Save ognjenm/0e772d584ac37f68a1cfc5f02010c9fc to your computer and use it in GitHub Desktop.
get Attachments from word document
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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