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

Free Support Forum - aspose.com

Generating word doc from a template

hi there

I am attempting to generate a document from a template.
I would like to read in the word doc, and then replace some placeholders with a number of tables

I have been perusing your documentation but cannot find anything that explains how to do this.

I can read in the template word doc fine, but have no idea how to find the placeholders in the template and then insert my tables (generated by some code/db queries etc).

i have even tried adding the tables in the ‘template’ but when i try doing
NodeCollection tc = doc.GetChildNodes(NodeType.Table, tryue);
it only finds 4 tables in the document, when in fatc there are more like 15…

could you enlighten me please.

many thanks


Dear Nat,

Thank you for question.

For your case I would recommend you use MailMerge functionality. Full information about it you can find here https://docs.aspose.com/words/net/mail-merge-and-reporting/. More itntently please see https://docs.aspose.com/words/java/types-of-mail-merge-operations/.

Please do not hesitate to ask more questions.

Hi Nat,

Thanks for your inquiry. Most likely, you use Aspose.Words in evaluation mode and document is truncated. That is why you get less number of tables than expected. There is evaluation limitation of maximum number of paragraphs in the document. You should see the following text in the output documents.
This document was truncated here because it was created using Aspose.Words in Evaluation Mode.
If you want to test Aspose.Words for without the evaluation version limitations, you can request a 30-day Temporary License. Please refer to
Best regards.


thanks for all that, yes now added the licence pat and all is fine.

I have mage the word doc tempalte with the mailmerge fields in it.
and as i want to replace these fields with a word table with some data in it…
am i to do this?

Table t1 = getMytable();
table t2 = getmytable2();// etc
object[] replacements = {t1,t2,…};

doc.MailMerge.execute(doc.mailmerge.getfieldnames(), replacements );

could someone enlighten me further please



Hi Nat,

Thank you for additional information. I think, in your case you should use mail merge with regions to fill table with data. Please follow the links to learn more about mail merge with regions:
Hope this helps. Please let me know if you need more assistance, I will be glad to help you.
Best regards,

Hi Nat,
Just to clarify the technique which my colleagues have already suggested.
Using mail merge you can merge data from your datasource into existing tables in your template. These tables will dynamically grow with each row of data from the datasource. You do not need to create tables manually and insert them.
You can find an example of this in action on the Demo pages here. If you installed Aspose.Words using the MSI installer you can find the full code and templates in the folder where Aspose.Words is installed to.