Free Support Forum - aspose.com

Merging Word Document Section is not working

Hi

I have the following code for merge multiple documents

Document doc = new Document();
Document doc1 = new Document(@"C:\Documents and Settings\Desktop\Test1.docx");
Document doc2 = new Document(@"C:\Documents and Settings\Desktop\Test2.docx");
Section section=new Section(doc1);
Section newSection = (Section)doc.ImportNode(section, true, ImportFormatMode.KeepSourceFormatting);
doc.AppendChild(newSection);
Section section1 = new Section(doc2);
Section newSection1 = (Section)doc.ImportNode(section1, true, ImportFormatMode.KeepSourceFormatting);
doc.AppendChild(newSection1);
doc.Save(@"C:\Documents and Settings\Desktop\Test3.docx");

Here am trying to merge doc1 and doc2 into doc

Am facing the following issues

1. In result "doc" am getting blank page in the begining

2. The doc2 contents are not displaying in final word out put

Please tell me where are doing wrong or please tell me how to merge multiple Documents into one final word document

Regards

Ajeesh

I think you’ll find the answer your looking for here.

Hi Ajeesh,


Thanks for your inquiry. Could you please attach your input Word documents here for testing? I will investigate the issues on my side and provide you more information.

Best regards,

Hi Awais Hafeez

Thanks for your reply

I got the solution for my problem in the previous mail.Now i have another query

I have one word template and i have a Dataset.In the dataset i have multile datatabe.Using one word template how to replace all the datatables in the dataset.Am using doc.MailMerge.ExecuteWithRegions method to bind.Am attaching my template here .I need Each datatable in dataset to be display in different pages

Regards

Ajeesh

Hi Ajeesh,


Thanks for your inquiry. There is only one MailMerge Region in your Template Word document (i.e. ReportTable); could you please clarify how exactly you require all the records in every DataTable of DataSet be merged in this single Region? May be you can take union of all Rows in DataTables and create a one big DataTable with the same name (ReportTable) as of your MailMerge Region. You can then use the following overload of ExecuteWithRegions method to perform mail merge from a DataTable into the document with mail merge regions

public void ExecuteWithRegions(DataTable);

Best regards,