I have two word templates in that one is containing fixed text and the other one is used for mailmerge contents. I have to merge these two documents together and display as one document. I have used the below code to implement this.
public void CreateWordDoc()
{
try
{
DataTable dtInfo = method to get data from db;
Document oDocApplns = new Document(@"C:\Temp\template2.doc");
oDocApplns.MailMerge.Execute(dtInfo);
Document oDoc = new Document(@"C:\Temp\template1.doc");
foreach (Aspose.Words.Section oSecAppln in oDocApplns.Sections)
{
Aspose.Words.Section oSrcSec = (Aspose.Words.Section)oDoc.ImportNode(oSecAppln, true);
oDoc.Sections.Add(oSrcSec);
// I have tried the below method also but it is not giving me the expected format.
// oDoc.Sections[oDoc.Sections.Count - 1].AppendContent(oSrcSec);
}
oDoc.ProtectionType = ProtectionType.ReadOnly;
oDoc.Save("MyTest.doc", SaveFormat.FormatDocument, SaveType.OpenInBrowser, Response);
}
catch (Exception oEx)
{
HttpContext.Current.Response.Write(oEx.Message);
}
}
The problem I am having here is,
The first template document is having roman letters and second template is having numeric page numbers like Page 1 of 3. I found that after mail merging , if 20 pages are there in the second document it’s repeating the page numbers i.e. Page 1 of 3, Page 2 of 3, Page 3 of 3 followed by Page 1 of 3,Page 2 of 3…,. Please provide a solution for this asap.
Thanks
Aneesh