importNode imports entire contents as Shape when any of the child nodes contain a Shape. I’m executing the below method. When the node and child nodes of the src document are all text (paragraphs with runs) it works as expected. I any of the child nodes is a shape the entire contents (node and all child nodes) are imported as a single non-editable Shape object. I expected that each node would be imported as the same node type as in the src document.
public static void setValue(final Document dstDoc, final String name, final Document srcDoc, final int importFormatMode)
throws WTException {
final Bookmark bookmark = dstDoc.getRange().getBookmarks().get(name);
Node destination = bookmark.getBookmarkStart().getParentNode();
if (!matchesAnyNodeType(destination, NodeType.PARAGRAPH, NodeType.TABLE)) {
throw new IllegalArgumentException("The destination node should be either a paragraph or table.");
}
final CompositeNode<?> destinationParent = destination.getParentNode();
final NodeImporter importer = newNodeImpter(srcDoc, destination.getDocument(), importFormatMode);
for (final Section section : srcDoc.getSections()) {
for (final Node node : (Iterable<Node>) section.getBody().getChildNodes()) {
if (node.getNodeType() == NodeType.PARAGRAPH) {
if (((Paragraph) node).isEndOfSection() && !((Paragraph) node).hasChildNodes()) {
continue;
}
}
final Node clone = importNode(importer, node, true);
destinationParent.insertAfter(clone, destination);
destination = clone;
}
}
}