MovetomergeField where the is more than one mergefield with the same name

Hi

I have a scenario that on the document we have mergefields with the same name added as below:

«TableStart:QuoteServicePrefix»«Description»«TableEnd:QuoteServicePrefix»
«TableStart:Services»
«ServiceName»«TableStart:MealBasis» («Name»)«TableEnd:MealBasis»
«TableEnd:Services»
«TableStart:ServiceDescriptions»«Description»«TableEnd:ServiceDescriptions»
«TableStart:QuoteServiceDescription»«Description»«TableEnd:QuoteServiceDescription»
«ServicePictures»
«TableStart:Locations»«Name»«TableEnd:Locations»
«TableStart:LocationDescriptions»«Description»«TableEnd:LocationDescriptions»
«LocationPics»
«TableStart:Suppliers»**«Name»**
«Grading»
«Telephone»
«Street», «City», «Code»
«Website»
«TableEnd:Suppliers»
«TableStart:SupplierDescriptions»«Description»«TableEnd:SupplierDescriptions»
«SupPicture»
«TableStart:QuoteServiceSuffix»«Description»«TableEnd:QuoteServiceSuffix»
«TableStart:OptionalPricing»For «TableStart:Currencies»«Code»«TableEnd:Currencies» «Amount» less«TableEnd:OptionalPricing»
«Pricing»

You will notice Descriptions merge field is the field in question and the Descriptions are coming from different tables.

How do I move to a particular mergeField , when we use builderLayout.MoveToMergeField('Description") it always returns the first one and so now we cannot insert new mergefield at the right position as it is always goner insert in reference to the first description merge field.

Secondly should we need to insert a new merge field after «TableEnd:ServiceDescriptions» how do we go about since movetomergefield does not recognise TableEnd and if we say Move toMergeField("ServiceDescriptions ") it will find The TableStart:ServiceDescriptions.

Lastly we have the above section repeated in another section and the new fields we want to insert should also be inserted in that section

Regards

Travelogic Developers

Hi Phillip,

Thanks for your inquiry and sorry for the delayed response.

It is the expected behaviour i.e. if your document contains multiple merge fields with the same name, the DocumentBuilder.MoveToMergeField method will always move to the first merge field. We will consider improving Aspose.Words’ API and provide a convenient method that allows jumping to desired merge field that is contained in a particular mail merge region. Your request has been linked to the appropriate issue in our issue tracking system and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Phillip:

Secondly should we need to insert a new merge field after «TableEnd:ServiceDescriptions» how do we go about since movetomergefield does not recognise TableEnd and if we say Move toMergeField("ServiceDescriptions ") it will find The TableStart:ServiceDescriptions.

Lastly we have the above section repeated in another section and the new fields we want to insert should also be inserted in that section

You can move the cursor to the end of your mail merge region (in each section) and insert an extra field there by using the following code snippet:

Document doc = new Document(@“C:\Temp\in.docx”);

DocumentBuilder builder = new DocumentBuilder(doc);

string regionName = “QuoteServicePrefix”;

NodeCollection fieldStarts = doc.GetChildNodes(NodeType.FieldStart, true);

foreach (FieldStart fieldStart in fieldStarts)

{

if (fieldStart.FieldType == FieldType.FieldMergeField)

{

StringBuilder sbuilder = new StringBuilder();

for (Node node = fieldStart; node != null && node.NodeType != NodeType.FieldSeparator &&

node.NodeType != NodeType.FieldEnd; node = node.NextPreOrder(node.Document))

{

// Use text only of Run nodes to avoid duplication.

if (node.NodeType == NodeType.Run)

sbuilder.Append(node.GetText());

}

string fieldCode = sbuilder.ToString();

if (fieldCode.Contains(“TableEnd:” + regionName))

{

// Move the cursor to be after the TableEnd field of the target region

builder.MoveTo(fieldStart);

// Search forward to find the end of the field.

Node currentNode = fieldStart.NextPreOrder(doc);

while (currentNode != null && currentNode.NodeType != NodeType.FieldEnd)

currentNode = currentNode.NextPreOrder(doc);

builder.MoveTo(currentNode);

// use builder.InsertField here

}

}

}

doc.Save(@“C:\Temp\out.docx”);

I hope, this helps.

Best regards,

Thank you for the help.

Note that in order for this code to work for us, in the last WHILE loop I had to replace ‘NodeType.FieldEnd’ with ‘NodeType.FieldStart’.

Regards

Hi Phillip,

It’s great you were able to find what you were looking for. Please let us know any time you have any further queries.

Best regards,

Hi,

I’m still looking for the promised method call.
Because in our scenario this workaround does not work.

Is there a timeline for the extension?

Greetings

Hi Christian,

Thanks for your inquiry. Unfortunately, your issue is not resolved yet. I have verified the status of this issue from our issue tracking system and regret to share with you that this issue has been postponed till a later date. We will be sure to inform you via this thread of any developments and let you know once it is resolved. We apologize for your inconvenience.

Best regards,

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.
(1)