Aspose.words needs


I’ve read through the info on your website and the above component appears to be close to what I require.

Let me first describe what our needs are and if you could let me know if the product is suitable.

We have hundreds of MS Word Documents with 10 merge fields already setup, these merge fields are placeholders for data stored in SQL Server.

We have a grid which users use to select the records/information they want to merge, unlike your standard mail merge process where only 1 Template is used to merge the data (eg like a letter mailout scenario), we have many Word Template documents. The Word Document File Name is unique and specific, every data row that is to be merge will have this file name. So essentially I need a component to read the records the user has selected, find the Word file on the server and merge the data in the merge fields and perform this process for every record the user has selected, then combined all of the merged documents into 1 Word File for them to either print to hardcopy or they may wish to print to PDF.

We currently have this working via automating MS Word on the server, but the process to make it work is unreliable as it involves a lot of server configurations. We are looking for a simpler solution with less security tweaks in windows 2003 server.

Hope I have provided sufficient information above for you to advise if your product will suit my needs.

Please also advise what your hourly consulting fees are as we may require this functionality to be developed by you and if possible could you quote the above requirements.

This message was posted using Email2Forum by Merit.

Thank you for your interest in Aspose.Words.
You can achieve what you need using Aspose.Words. I created simple example for you. See the following code:

// Prepare datasource
DataTable table = new DataTable();
// Add data to datasource
table.Rows.Add(new object[] { @"Test212\in1.doc", "Alexey", "Noskov" });
table.Rows.Add(new object[] { @"Test212\in2.doc", "Bill", "Tompson" });
// Loop through rows in datasource
int i = 0;
foreach (DataRow row in table.Rows)
    string fileName = row["FileName"].ToString();
    // Open template
    Document doc = new Document(fileName);
    // Perform mail merge
    // Save document
    doc.Save(string.Format(@"Test212\out_{0}.doc", i));
You can merge documents together using the following code:
Document dstDoc = new Document(@"Test103\Template1.doc");
Document srcDoc = new Document(@"Test103\Template2.doc");
foreach (Section srcSection in srcDoc.Sections)
    Node dstSection = dstDoc.ImportNode(srcSection, true, Aspose.Words.ImportFormatMode.KeepSourceFormatting);

Then you can convert document to pdf, see the following link for more information.
You can also print document, but this feature is currently in beta and limited technical support is provided for it. See the following link
Best regards.

thank you for your reply.
your code is in C # i think… do you have the same code in ?
thank you in advance.

Hi Jerry,
Here is the same code in VB.

'Prepare datasource
Dim table As DataTable = New DataTable()
'Add data to datasource
table.Rows.Add(New Object() {"Test212\in1.doc", "Alexey", "Noskov"})
table.Rows.Add(New Object() {"Test212\in2.doc", "Bill", "Tompson"})
'Loop through rows in datasource
Dim i As Integer = 0
For Each row As DataRow In table.Rows
Dim fileName As String = row("FileName").ToString()
'Open template
Dim doc As Document = New Document(fileName)
'Perform mail merge
'Save document
doc.Save(String.Format("Test212\out_{0}.doc", i))
i += 1
And here is second code snippet.
Dim dstDoc As Document = New Document("Test103\Template1.doc")
Dim srcDoc As Document = New Document("Test103\Template2.doc")
For Each srcSection As Section In srcDoc.Sections
Dim dstSection As Node = dstDoc.ImportNode(srcSection, True, Aspose.Words.ImportFormatMode.KeepSourceFormatting)

Best regards.

thank you for your code. can aspose.words use a dataset as a datasource? reason being the data i need for merging comes from various tables in the database.
i can easily generate this data and store it in a dataset however the column names differs from the MergeField names in MSWord documents.
would you be able to provide a code to overcome an issue where the MergeField in MS Word is different to table column names.

Thanks for your inquiry.
You can use DataSet as datasource for mail merge with regions. See the following link for more information.
For simple mail merge you can use DataView. See the following link
Also the MailMerge class allows to automatically map between names of fields in your data source and names of mail merge fields in the document. Please see the following link for more information.
Hope this helps.
Best regards.

Hi alexey
thank you for the links.
after reading through the “mapped data fields” documentation, i need some guidance as to how the code will look. see example below: code;

Dim doc As Document = New Document(test.doc")
doc.MailMerge.Mapped DataFields.Add("BKProjectCode,BKEquipmentNumber,BKEquipDescription","ProjectCode,EquipmentNumber,EquipDescription")

is this correct? or should it be as follows;

Dim doc As Document = New Document(test.doc")
doc.MailMerge.Mapped DataFields.Add("BKProjectCode","ProjectCode")
doc.MailMerge.Mapped DataFields.Add("BKEquipmentNumber","EquipmentNumber")
doc.MailMerge.Mapped DataFields.Add("BKEquipDescription","EquipDescription")


Thanks for your inquiry. The second method is correct. Please see API reference for more information.
Best regards.