Hello,
I have a set of documents that uses merge fields. Some of the documents have multiple mergefields with the same name. Is there a way to use MoveToMergeField to traverse the mergefields? When I use it right now, it keeps taking me to the first mergefield in the document. I would think it should move to the next field with the same name if it is called again. I would think this is possible because the MailMerge updates all the mergefields correctly including the duplicate merge fields.
string[] mergeFields = oDoc.MailMerge.GetFieldNames();
foreach (string field in mergeFields)
{
iFieldCount++;
iMasterCount++;
oBuilder.MoveToMergeField(field, false, false);
oBuilder.StartBookmark(field + @"_" + iMasterCount.ToString());
oBuilder.MoveToMergeField(field, true, false);
oBuilder.EndBookmark(field + @"_" + iMasterCount.ToString());
}
oDoc.Save(searchDocument, Aspose.Words.SaveFormat.Docx);
This is code I am using that keeps going to the first mergefield in the document.
Thanks for any help,
Bryan
Hi Bryan,
Thanks for your inquiry.
I managed to reproduce the issue on my side, your request has been linked to the appropriate issue. We will inform you as soon as it’s fixed.
In the mean time, please try using this code below instead.
NodeCollection fieldStarts = oDoc.GetChildNodes(NodeType.FieldStart, true);
foreach(FieldStart start in fieldStarts)
{
if (start.FieldType == FieldType.FieldMergeField)
{
iFieldCount++;
iMasterCount++;
oBuilder.MoveTo(start);
oBuilder.StartBookmark(mergeFields[iFieldCount - 1] + @"_" + iMasterCount.ToString());
// Search forward to find the end of the field.
Node currentNode = start.NextPreOrder(oDoc);
while (currentNode != null && currentNode.NodeType != NodeType.FieldEnd)
currentNode = currentNode.NextPreOrder(oDoc);
oBuilder.MoveTo(currentNode);
oBuilder.EndBookmark(mergeFields[iFieldCount - 1] + @"_" + iMasterCount.ToString());
}
}
If we can help you with anything else, please feel free to ask.
Thanks,
The issues you have found earlier (filed as WORDSNET-5111) have been fixed in this .NET update and this Java update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.