Free Support Forum - aspose.com

Issue changing Mergefield names

For some reason, when I change the mergefield names, some issues arrise.

  1. \*MERGEFORMAT becomes \m
  2. Quotes appear around the merge name. Unfortunately, salesforce cannot recognize mergefields with quotes around them

Example:
In a document, I can have a mergefiled called «representativename». When I toggle field codes, it looks like:
{ MERGEFIELD representativename \* MERGEFORMAT }

When I run the change routine, it becomes:
{ MERGEFIELD "USER_FULLNAME" \m }

The code we use was taken from this site a while back, so it may be outdated. I modified it slightly to fit the thread...


Dim doc As Document = New Document(inDoc)
Dim fieldStarts As NodeList = doc.SelectNodes("//FieldStart")
For Each fieldStart As FieldStart In fieldStarts
If (fieldStart.FieldType = FieldType.FieldMergeField) Then
Dim mergeF As Mergefield = New Mergefield(fieldStart)
'Code will need to check for current name here, replace if matched.
if replace(replace(CStr(mergeF.Name), "«", ""), "»", "") = "representativename" then
mergeF.Name = "USER_FULLNAME"
End If
End If
Next fieldStart
doc.Save(inDoc)
doc = nothing

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

Hi

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

Thanks for your request. I cannot reproduce the problem on my side. I used your code and the latest version of Aspose.Words for testing. You can download the latest version of Aspose.Words from here:

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

I also attached MergeField class, I used for testing. By the way, it is the same as provided here:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/howto-rename-merge-fields.html

Also, could you please attach a simple document, which you are using for testing. I will check it and provide you more information.

Best regards.