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

Free Support Forum - aspose.com

Modified mailmerge fields names and MailMerge.execute

In my program:

  1. I find a table row with some mailmerge fields
  2. I clone the row and append it after the original one (many times, i.e. I create many new rows with same mailmerge fields inside )
  3. I rename those new mailmerge fields, adding row number at the end of the name (so, I’ll have Name1, Name2, Name3…)
  4. I make doc.MailMerge.Execute(keys, values), where keys and values are two arrays with data
    for mailmerge
  • keys and values contain also Name1, Name2, etc…, obviously result is: all other mailmerge fields in the document are filled in, but my newly created fields remain unfilled.

What am I doing wrong?


Thanks for your request. May I ask why you choose so complicated way to fill your template with data? I think, in your case you should just use mail merge with regions:
Also, please attach your template, intermediate document (with all merge fields inserted) and output document here for testing.
Best regards.

Modulo_1.doc is the original file Pippo.doc is the document after the duplication od rows 34570320102416656. docx is the merged document(don 't watch docx extension, it makes the same thing also with .doc files)

Tomorrow I see MailMerge regions, but I’d like to know where I am doing wrong.


Thank you for additional information. The problem occurs because you rename merge field improperly. During renaming, you break field code. Code of merge field should be like the following:
{ MERGEFIELD fieldName }
But after renaming, your intermediate document contains fields with code like the following:
{ fieldName }
Such fields are no longer merge field that is why they are ignored. You should press Alt+F9 in MS Word to see field codes.
Also, please see the following link to learn how to rename merge fields properly:
Best regards.

I follow that example, making cut & paste of classes in my code.
The code to change the name is:

foreach(FieldStart CampoUnione in UnioneInRiga)
    if (CampoUnione.FieldType.Equals(FieldType.FieldMergeField))
        MergeField Campo = new MergeField(CampoUnione);
        Campo.Name = Campo.Name + "1";

I don’t know why mergefield code has changed.
I attach my code file.
Thanks for support

I’ve found a way:

Campo.Name = "MERGEFIELD " + Campo.Name + w.ToString();

in place of

Campo.Name = Campo.Name + w.ToString();

and now it works.
Now I’ll try with regions, thanks for your support


It is perfect that you fond solution. But anyways, I think, mail merge with regions will better fit your needs.
Best regards,