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

Free Support Forum - aspose.com

MailMerge How can you add bullet to conditional merge clause

Hi can anyone show me how to add a bullet (not a bullet symbol I will need to be able to continue the bullets after merging.) to a conditional mergefield clause?
ie.

{MERGEFIELD TableStart:ConditionalPara}
{if {MERGEFIELD ConditionalParaId } = “second” "{MERGEFIELD TableStart:LDC} insert bullet here{MERGEFIELD AssnText} {MERGEFIELD TableEnd:LDC}
{MERGEFIELD TableEnd:ConditionalPara}

Thanks,
Michael

Hi Michael,

Thanks for your inquiry. I suggest you please implement IFieldMergingCallback interface if you want to control how data is inserted into merge fields during a mail merge operation. In your case, I suggest you please use following code snippet to achieve your requirements. Hope this helps you.

If you still face problem, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

public class HandleMergeFieldTest : IFieldMergingCallback
{
    DocumentBuilder builder;
    Aspose.Words.Lists.List list;
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
    {
        if (builder == null)
            builder = new DocumentBuilder(e.Document);
        if (list == null)
            list = e.Document.Lists.Add(ListTemplate.NumberDefault);
        if (e.DocumentFieldName.Equals("AssnText"))
        {
            builder.MoveToMergeField(e.DocumentFieldName);
            builder.ListFormat.List = list;
            builder.Writeln("Field value");
            builder.ListFormat.RemoveNumbers();
            e.Text = "";
        }
    }
    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
    {
        // Do nothing.
    }
}

Hi Tahir,

Thank you for that piece of code. I’m almost at what I want to see as an output.

I’m having some clean up issues now with the merge conditions left behind:

This is the current output: see jpg attachment

When I hit ctr+F9 the merge conditions disappear but leave behind empty lines: ie

• adheres to Policy 1.2.1–Locally Developed/Acquired and Authorized Junior and Senior High School Complementary Courses

• does not have significant overlap with provincial programs of study.

• my test

I’ve also attached the template for reference

Hi Michael,

Thanks for your inquiry. The MailMerge.CleanupOptions property is used along with the MailMergeCleanupOptions enumeration to specify different options on how the mail merge engine deals with such left over merge fields.

In your case, I suggest you please use MailMergeCleanupOptions.RemoveContainingFields flag with MailMerge.CleanupOptions. Please read following documentation link for your kind reference.
https://docs.aspose.com/words/net/clean-up-before-or-during-mail-merge/

If you still face problem, please share following detail for investigation purposes.

  • Please

create a standalone/runnable simple application (for example a Console
Application Project
) that demonstrates the code (Aspose.Words code) you used to generate
your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

I am already using all the clean up options.

doc.MailMerge.CleanupOptions = MailMerging.MailMergeCleanupOptions.RemoveContainingFields _
Or MailMerging.MailMergeCleanupOptions.RemoveEmptyParagraphs _
Or MailMerging.MailMergeCleanupOptions.RemoveUnusedFields _
Or MailMerging.MailMergeCleanupOptions.RemoveUnusedRegions _
Or MailMerging.MailMergeCleanupOptions.RemoveContainingFields

The clean up only seems to work 2 level deep.

Hi Michael,

Thanks for your inquiry. Please share following detail for investigation purposes.

  • Please

create a standalone/runnable simple application (for example a Console
Application Project
) that demonstrates the code (Aspose.Words code) you used to generate
your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

Please find attached the console app and target output

Hi Michael,

Thanks for sharing the detail. I have modified your template document and have attached it with this post. See the attached image for detail. For this modified document, you do not need to implement IFieldMergingCallback. Hope this helps you.

doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveContainingFields;
doc.MailMerge.CleanupOptions |= MailMergeCleanupOptions.RemoveEmptyParagraphs;
// doc.MailMerge.CleanupOptions |= MailMergeCleanupOptions.RemoveUnusedRegions;
// doc.MailMerge.CleanupOptions |= MailMergeCleanupOptions.RemoveUnusedFields;
// doc.MailMerge.FieldMergingCallback = new HandleConditionalMergeFieldList();
doc.MailMerge.ExecuteWithRegions(ds);

Thank you so much!!

Hi Michael,

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