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

Free Support Forum - aspose.com

Insert text with mergefield from database

Hi,

I have a small paragraph of text that contains a mergefield that I want to insert into my main document.

The text is something like…
By upgrading the «NameOfSuperFund» to a modern day trust deed etc etc

I would like to store the text in a table in a sql server database. How can I get the mergefield into the sql database table?

My idea is that I would do a two step merge. The first step would insert the paragraph containing the mergefield into the document. The second step would then replace the mergefield «NameOfSuperFund» with the required text.

thanks
Peter

Hi Peter,


Thanks for your inquiry.

I think you can achieve what you are looking for by implementing the following work flow:

1) Create a MS WORD template document that contains your paragraph and the desired MergeField somewhere inside this paragraph.
2) To be able to store this document in SQL database, please read that document using Aspose.Words into stream by using the following link:
http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.document.save_overload_4.html
3) Later, you can fetch this stream information from DB and load into Aspose.Words Document instance for Mail Merge; please see the following link for more information about Mail Merge process:
http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-execute-simple-mail-merge.html

Please let us know if you need more information, We are always glad to help you.

Best Regards,

Hi,

when I merge the template document in step three will it add just the paragraph of text or a whole page?

thanks
Peter

Hi,


Thanks for your request.

Once you load the template document from database into the Document instance of Aspose.Words and execute a mail merge operation, in case if you are not using mail merge regions then the mail merge will be similar to Microsoft Word mail merge and the whole document content (template) will be repeated for each record in the data source. So, it depends on the number of records you have in the data source e.g. for N number of records this template will be repeated N times. For more information, please see the following link:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/about-mail-merge-in-aspose-words.html

Hope this helps.

Best Regards,