Hi
Thanks fro your inquiry. I think that you can try using MergeField event
to achieve this. See the following link for more information.
http://www.aspose.com/Products/Aspose.Words/Api/Insert_One_Document_into_Another_during_Mail_Merge.html
Also here is code example for you. Template is attached.
public void TestMailMerge_106928()
{
string connString = "server=Web1;database=TestDB;uid=sa;pwd=password;";
System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connString);
//create DataSet
DataSet ds = new DataSet();
//Create sql command
string commandString = "SELECT
* FROM WMLDocs";
System.Data.SqlClient.SqlCommand command = new
System.Data.SqlClient.SqlCommand(commandString,
conn);
//create adapter
System.Data.SqlClient.SqlDataAdapter
adapter = new System.Data.SqlClient.SqlDataAdapter(command);
conn.Open();
//fill dataset
adapter.Fill(ds);
conn.Close();
ds.Tables[0].TableName = "WMLDocs";
Document doc = new
Document(@"433_106928_heywasabi\in.doc");
doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField_106928);
doc.MailMerge.ExecuteWithRegions(ds);
doc.Save(@"433_106928_heywasabi\out.doc");
}
void MailMerge_MergeField_106928(object
sender, MergeFieldEventArgs e)
{
if (e.FieldName == "body")
{
byte[] body = Encoding.UTF8.GetBytes(e.FieldValue.ToString());
MemoryStream stream = new
MemoryStream(body);
Document doc = new
Document(stream);
DocumentBuilder builder = new
DocumentBuilder(e.Document);
builder.MoveToMergeField(e.DocumentFieldName);
// Content of the specified document are inserted after the
paragraph, containing the merge field.
InsertDocument(builder.CurrentParagraph,
doc);
// If the paragraph, containing merge field, does not
contain anything else - delete it.
if (builder.CurrentParagraph.ToTxt().Trim() == "")
builder.CurrentParagraph.Remove();
// The field value text is not needed anymore, eraze it.
// Otherwise, it will be inserted at merge field location
too.
e.Text = string.Empty; ;
}
}
WML document is stored as XML. Here is WMLDocs table.
WMLDocs
|
ID
|
int
|
name
|
nvarchar(50)
|
body
|
XML
|
InsertDocument method you can find here.
http://www.aspose.com/Products/Aspose.Words/Api/Insert_One_Document_into_Another_at_Any_Location.html
I hope that this will help you.
Best regards.