I was wondering if Aspose could be use to do some drag and drop over an open document. I Would like to drag a merge field from java, and drop it over word on a given document.
It seems this could be done only if the drag context contains some word content, not only text, and I guess Aspose manage this content as needed.
Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thanks for your inquiry. Actually MergeField consists of several nodes (FieldStart, FieldSeparator, FieldEnd and several Runs). If you need to move MergeField you should move all nodes between FieldStart and FieldEnd nodes (including FieldStart and FieldEnd of course). Here is code example how you can achieve this.
Document doc = new Document("in.doc");
//Get collection of field starts
NodeCollection starts = doc.getChildNodes(NodeType.FIELD_START, true);
//For exampel we woold like to move the first mergefield in document
FieldStart mergefieldStart = null;
//Search for first mergefield start
for (int i = 0; i < starts.getCount(); i++)
FieldStart currentStart = (FieldStart)starts.get(i);
if (currentStart.getFieldType() == FieldType.FIELD_MERGE_FIELD)
mergefieldStart = currentStart;
if (mergefieldStart != null)
//We should copy all nodes between FieldStart and FieldEnd
ArrayList nodesList = new ArrayList();
//Write all nodes between start and end into ArrayList
Node currentNode = mergefieldStart;
while (currentNode.getNodeType() != NodeType.FIELD_END)
currentNode = currentNode.getNextSibling();
//Now we would like to move our mergefield to the end of document
for (int nodeIndex = 0; nodeIndex < nodesList.size(); nodeIndex++)
Hope this helps.