I have created a few templates with Word, but have always had the data source available at the time I was creating the document.
Can you tell me how Aspose will handle the following situation:
- Client creates a merge template (letter) for a complaint. At the time he is creating the template, he is working in Word and does not have a direct link to the database. How will he be able to input merge codes that relate to the fields of the database? I can provide a list, but I recall Word had a drop down menu of the available fields which are not available at document time.
- Document gets saved to be used by Aspose
- User enters a complaint, selects Print Letter and the complaint data is merged with the template and the corresponding document is displayed on the screen (to be printed or saved locally).
Thank you.
Well, you just need to know the names of the database table fields at the time of creation of your template. You can retrieve them by looking at the database schema or using some other tool that allow you to look at the data tables structure. Anyway, the client needs to know the set of field names before he starts creating the template. The actual process of creating merge fields is well described in Aspose.Words documentation. Here, for example:
https://docs.aspose.com/words/net/mail-merge-template/
In case that due to some reason the field names in the prepared template are different from the names in the datasource, there are two ways you can handle it. First, you can change them at the time of getting the data from database into the application data source (DataSet, DataTable, DataRow, etc.) using SQL SELECT with aliases query. E.g. “SELECT UserName as ClientName FROM Users”. Second, you can use field names mapping provided by Aspose.Words API, it is described here:
https://docs.aspose.com/words/net/mail-merge-and-reporting/
Concerning your last point about displaying and printing the document, please note that Aspose.Words only works with documents as a files. It does not display or print them yet. You need to use MS Word for this. To save the resulting document and open it in MS Word from your application you can use the following code:
internal static void SaveShow(Document document, string fileName)
{
document.Save(fileName);
System.Diagnostics.Process.Start(fileName);
}
Ability to display and print documents will be added to Aspose.Words later in 2007.
Hope this answers your question.
Best regards,