Free Support Forum - aspose.com

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

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/simple-mail-merge-explained.html

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/mail-merge-with-regions-explained.html

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

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry.

1. I think, you can use MergeField event handler to achieve what you need.

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/the-mergefield-event.html

2. You can use MergeField event handler to insert HTML content during mail merge:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.reporting.mergefieldeventhandler.html

3. There is no direct way to populate nested regions using Aspsoe.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.

http://www.aspose.com/demos/file-format-components/aspose.words/csharp/general/product-catalog.aspx

Hope this helps.

Best regards.

the below link is a no op

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.reporting.mergefieldeventhandler.html

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.reporting.mergefieldeventhandler.html

Hope this helps. Please let me know if you need more assistance, I will be glad to help you.

Best regards.