Loop tag

Hi,

We generally looking for a “template solution” based on Aspose Word. E.g. having some word document, place some “tags” there, run this document thru some “template engine code” that will replace tags with real data.
It seems very straightforward to do that with Document.getRange().replace(…), but what about loops and maybe if statements.
Any ideas, suggestion how to do that with Aspose Word API?
We had the similar solution working based on RTF and have done it succesfully with Velocity, but here we need somthing else in place of Velocity.

Thanks a lot.

Michael
michael@digitalfuel.com

Hi

Thanks for your inquiry. I think the best way to fill a Word template with data is using mail merge feature. Please follow the links to learn more about mail merge:
https://docs.aspose.com/words/net/types-of-mail-merge-operations/
Best regards.

Thanks,
I guess this is the way to go with Aspose for the similar functionality we have wit hour RTF custom tags.
However I have few issues I do not know how to implement with MailMerge.

  1. Run time Context: most of the tags we have in the document have ID, e.g. in run time this is evaluated and based on this ID the right “query” should be executed to fetch the results for the merge. In case of mail merge it seems to be no support for such “run time” data source resolution. If it is true it makes the whole process much more constraint in a way generic templates can be created?
  2. We need to be able to merge HTML pieces (like images: image merge), there seem to be no supporting function for that, is it possible?
  3. Is there a way to support inner merge regions (region within other region)?

Thanks
Michael
michael@digitalfuel.com

Hi

Thanks for your inquiry.

  1. I think, you can use MergeField event handler to achieve what you need.
    https://reference.aspose.com/words/net/aspose.words.mailmerging/ifieldmergingcallback/
  2. You can use MergeField event handler to insert HTML content during mail merge:
    https://reference.aspose.com/words/net/aspose.words.mailmerging/ifieldmergingcallback/
  3. There is no direct way to populate nested regions using Aspose.Words. It is possible, however, to generate the above reports by performing mail merge several times and building up a resulting document from several documents or fragments. The Product Catalog and Sales Invoice samples in the demo project supplied with Aspose.Words demonstrate the suggested techniques.
    https://github.com/aspose-words/

Hope this helps.
Best regards.

the below link is a no op
https://reference.aspose.com/words/net/aspose.words.mailmerging/ifieldmergingcallback/

Hi

Thanks for your request and my apologizes for inconvenience. The link was broken after refactoring our documentation some time ago. Here is correct link to this article:
https://reference.aspose.com/words/net/aspose.words.mailmerging/ifieldmergingcallback/
Hope this helps. Please let me know if you need more assistance, I will be glad to help you.
Best regards.