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

Free Support Forum - aspose.com

More flexible MailMerge?

In https://forum.aspose.com/t/128278 I read that it is not possible to delete certain parts of a document on empty fiels when doing MailMerge.

I do something like in your “SalesInvoiceDemo.doc” and want to remove content inside the “?TableStart:Orders?”/"?TableEnd:Orders?"-child-section.

Is it possible to work-around with something like putting another “?TableStart:?”/"?TableEnd:?"-section inside the “?TableStart:Orders?”/"?TableEnd:Orders?"-section?

What would be the best solution is something like that:

?AsposeBlockStart:RemoveIfNullOrEmpty(FieldNameToCheck)?
This block only gets outputted if the database
field FieldNameToCheck is non-empty.
?AsposeBlockEnd:RemoveIfNullOrEmpty?

Is this possible? Is there an upcoming release to support this? (I would be glad to beta-test something like this)

Thanks
Uwe

Hi Uwe,

Unfortunately, nested merge regions are not supported at the moment.

But your suggestion actually looks tempting, thank you. We haven’t planned to add something like that so far because possibility of removing a whole block was requested quite rarely and use of RemoveEmptyParagraphs seemed enough. We will probably implement this type of functionality though. We will let you know about the progress.

Thank you, Dmitry!

I could, if you are interested, specify some more kind of “SmartRegion”-options other than the one example I wrote in my original posting.

Thanks
Uwe

Thank you very much for this offer. You are welcome to post your suggestions and we will certainly consider them. However, in regard to this particular problem, at the moment I am not sure when and in what way exactly this possibility will be implemented. The only thing I can promise now is that we will surely notify you as soon as any progress has been made.

Thank you for understanding.

Damn! Last week I posted a reply with some pseudo-code, and now it seems to be gone.

Do I have to post it again?

Sorry Uwe, I can see some pseudo-code in the first post but nowhere else, no posts seemed to be done except the two existing ones.

OK, so I give it another try :

So here is my suggestion on how to extend the MailMerge.
Instead of just removing a section when a certain field is empty, I would suggest a more flexible approach:
?AsposeBlockStart: Dynamic(UniqueBlockID)?
Block with arbitrary content.
?AsposeBlockEnd: Dynamic?
Whenever such a block is detected during processing, a user-defined event-handler (similar to the current handler for images) is called. The handler could look like:

private void asposeWord_DynamicBlockDetected(object sender, Aspose.Word.DynamicBlockDetectedArgs e)
{
    if (e.UniqueBlockID == "*MyUniqueBlockID*")
    {
        if (SomeCondition)
        {
            e.BlockOperation =
            Aspose.Word.DynamicBlockOperation.Remove;
        }
    }
}

With the following types:

namespace Aspose.Word
{
    // ...
    // /

    // / The operation to perform on the block.
    // /

    public enum DynamicBlockOperation
    {
        LeaveUnchanged,
        RemoveBlock,
        ModifyBlock,
        // ...
    }

    public class DynamicBlockDetectedArgs :
    System.EventArgs
    {
        public string UniqueBlockID; // [in]
        public DynamicBlockOperation BlockOperation; // [out]
        public Range Block; // [in,out]
        // ...
    }
}

It should be possible to nest these blocks for maximum flexibility.
This is my basic suggestion. Maybe it is useful for you in some way and hopefully you can implement something like this in the near future .
Thanks
Uwe

One addition: As I found out in this posting: https://forum.aspose.com/t/128151 the solution described there is almost enough for me.

The only thing I’m missing is the ability to delete content from the DocumentBuilder class.

Maybe this is easy to implement in a following version.

Thanks
Uwe

Thank you for your great suggestion.

The ability to delete existing content will get available as soon as we switch to the new object model we’re working on. Currently this is not possible to implement.

Hi Dmitry

Just being rather curious : Any news on when you release a new version with the “new object model” you mentioned?

Thanks
Uwe

Hi Uwe,

This version is out, this is v3.0 Its object model allows to do with Word much more things than using the builder and deleting existing nodes is just a little part of the possibilities… Please download it to test and play with the model.

We are happy to tell you that the new version of Aspose.Words, which we have just released, supports mail merge with nested regions. You can download the latest version of Aspose.Words from here:https://releases.aspose.com/words/net