Difficulty using merge fields for bullet list.

I am using Gembox in a .NET project. I want to use bullets point to display a list of numbers I have. So I use merge fields for this bullet “PhoneNumberList”. But when I execute merge fields, the result is still only 1 bullet as before. Please see the picture. Please let me know if my usage is correct and how to fix it. Thank you very much.

Please help me. Everyone

Hi,

List items are paragraph elements, so you will need to generate multiple paragraphs to achieve the desired result.

For example, you could have a “PhoneNumberList” merge range:

Then you could use the following data source:

var document = DocumentModel.Load("input.docx");

var source = new
{
    PhoneNumberList = new[]
    {
        new { Value = "01117282282" },
        new { Value = "09991812723" },
        new { Value = "09897226511" }
    }
};

document.MailMerge.Execute(source);

document.Save("output.docx");

And the result would be:


Or if you want to use your current approach:

You’ll need to customize the mail merge process.
For example, try something like this:

var document = DocumentModel.Load("input.docx");

document.MailMerge.FieldMerging += (sender, e) =>
{
    if (!e.IsValueFound || e.Value is null)
        return;

    var allInlines = e.Inlines.ToArray();
    e.Inlines.Clear();

    var currentInlines = e.Inlines;
    var paragraph = e.Field.Parent as Paragraph;

    for (int i = 0; i < allInlines.Length; i++)
    {
        var specialCharacter = allInlines[i] as SpecialCharacter;
        if (specialCharacter is null || specialCharacter.CharacterType != SpecialCharacterType.LineBreak)
        {
            currentInlines.Add(allInlines[i]);
        }
        else
        {
            var clonedParagraph = paragraph.Clone(false);
            paragraph.ParentCollection.Insert(paragraph.ParentCollection.IndexOf(paragraph) + 1, clonedParagraph);
            currentInlines = clonedParagraph.Inlines;
            paragraph = clonedParagraph;
        }
    }
};

var source = new
{
    PhoneNumberList =
@"01117282282
09991812723
09897226511"
};

document.MailMerge.Execute(source);

document.Save("output.docx");

I hope this helps.

Regards,
Mario