We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Merge Field - Merge field has space in between field name

Below are the mail merge field in word
{MERGEFIELD Application Number * MERGEFORMAT}

{MERGEFIELD “Docket Number” \m * MERGEFORMAT}


We are using Aspose.words -9.0.0.0.

MailMerge.GetFieldNames() retrieved as follows -> Application / Docket Number

Why its not getting as it is -> Application Number / Docket Number

Thanks

Hello

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I cannot reproduce the problem on my side using the latest version of Aspose.Words (9.4.0). I use the following code for testing:

Document doc = new Document("in.doc");

// Loop through all Field Names

foreach (string fieldName in doc.MailMerge.GetFieldNames())

{

Console.WriteLine(fieldName);

}

You can download the latest version from here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx

Best regards,

I tried with latest aspose.words.dll.

May be i was wrong in giving the field. Not sure. So i am attaching the Document which i have problem.


Hello

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is fixed.

It seems there is something wrong with these MergeFields. If you for example try renaming them and save, the problem disappears.

Best regards,

I would like to add one more point to it. it works fine with 5.2.0.0

Thank you for additional information. We will be sure to inform you of any developments regarding this issue.

Best regards,

Can you please let us know when this will be fixed and released? We need to inform our client and buy some time (we are holding our work)

Thanks

Hello

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Unfortunately, I cannot provide you any reliable estimate regarding this issue at the moment. But I think you can try parsing field code to retrieve correct field name. Please see the following code example which shows how to get field code:

Document doc = new Document("Testing+.doc");

// Get collection of FieldStarts

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

// Loop through all Field Starts

foreach (FieldStart fieldStart in fieldStarts)

{

if (fieldStart.FieldType.Equals(FieldType.FieldMergeField))

{

Console.WriteLine(GetFieldCode(fieldStart));

}

}

private static string GetFieldCode(FieldStart fieldStart)

{

StringBuilder builder = 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)

builder.Append(node.GetText());

}

return builder.ToString();

}

If you need any further assistance, please feel free to ask.

Best regards,