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

Free Support Forum - aspose.com

Separators in enumeration in mail merge region

Hi,

I would like to insert an enumeration with Region Mail Merge.
I have two problems:

  • Each element of the loop, starts in a new line.
  • I would like to have a separator (comma) between the loop elements, except for the last element.

My word document looks like this:

«TableStart:Loop1»«placeholder», «TableEnd:Loop1»

My output is:

Text1,
Text2,
Text3,
Text4,
Text5,

My output should be:

Text1, Text2, Text3, Text4, Text5

How can I do that?

Kind Regards
Peter

@GEDAT

Thanks for your inquiry. In your case, we suggest you please use MailMerge.UseWholeParagraphAsRegion property. Set the value of this property as false as shown below.

This property is used to get or set a value indicating whether whole paragraph with TableStart or TableEnd field or particular range between TableStart and TableEnd fields should be included into mail merge region.

Document doc = new Document(MyDir + "in.docx");
doc.MailMerge.UseWholeParagraphAsRegion = false;

Hope this helps you.

Hi Tahir,
thank you for your answer. That solved one of my two problems :slight_smile:
Now the Text is in one line.
But how can i insert Separators? (Text or Char, only between the elements of a Region)
If I fill the MailMergeField.TextAfter with the text “, ” I have a separator at the end, I don’t need:
Text1, Text2, Text3, Text4, Text5,

The output I need is:
Text1, Text2, Text3, Text4, Text5

Kind Regards
Peter

@GEDAT

Thanks for your inquiry. In this case, we suggest you please set the text before field as ", " in your input document. Please implement IFieldMergingCallback interface as shown below to get the desired output.

Document doc = new Document(MyDir + "in.docx");

doc.MailMerge.UseWholeParagraphAsRegion = false;
doc.MailMerge.FieldMergingCallback = new FieldMerging_Callback();
doc.MailMerge.ExecuteWithRegions(......);
                 
doc.Save(MyDir + "18.10.docx");

public class FieldMerging_Callback : IFieldMergingCallback
{

    public void FieldMerging(FieldMergingArgs e)
    {
        if (e.RecordIndex == 0)
            e.Field.TextBefore = "";
    }

    public void ImageFieldMerging(ImageFieldMergingArgs args)
    {
              
    }            
}

Hi Tahir,
thank you for your answer.
This solution works for me.

Thank you.
Kind regards

Peter

@GEDAT

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.