About merging word documents

Hi Team,
I am trying to merge 2 word documents into one and then export the final copy to pdf.
One of these documents is created using custom templates. when i merge, there is a section in destination document which should be replaced by text of source document. But rather than merging it just appends the text from the source document into destination document.
I am using following code.

const string path = "c:\\abc\\";
var groupDocument = new Document(path + "group.docx");
var detailsDocument = new Document(path + "details.doc");
detailsDocument.AppendDocument(groupDocument, ImportFormatMode.KeepSourceFormatting);


Here the first section of the details document should be replaced by the content of the groupDocument.
Please help ??

Hi Bhushan,

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

PS: You can create the expected / target document using Microsoft Word application.

Best regards,

Please find attached documents. I want to merge analysis.doc into header doc. In that contents of header.doc should replace the first section of analysis.doc which is written as Reserved for pdf static data section. But doing this should not affect the rest of the document. I mean wherever the page is ending initially in the analysis.doc, it should still end at the same position, which doesnt happen. Also it should maintain alignments and other styles of the source documents. We have implemented this currently using word application but after merging the docs, the final copy sometimes misses the page breaks by one or two sentences up or down, and bullets gets changed etc. So we thought of using Aspose and we are sure it should be very easy and performance tuned with Aspose.

Hi Bhushan,

Thanks for the additional information. You can use the following code snippet to be able to insert one document at the specified location in another document:

Document docAnalysis = new Document(@"C:\Temp\analysis.doc");
Document docHeader = new Document(@"C:\Temp\header.docx");
InsertDocument(docAnalysis.FirstSection.Body.Tables[0], docHeader);

I hope, this helps.

Moreover, I would refer you to the following sections of the documentation which outlines everything you need to know about inserting a Document into another Document:

Best regards,