Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files from any .NET platform (C#, VB.NET, ASP.NET, .NET Core) and Java applications (J2SE and J2EE) with fast and high quality performance.

Tue Jul 26, 2022 12:36 pm

Hello,
i'm trying to merge multiple word document into one document, but I would like the order to be my choice.

Document doc = new Document();

//document1
doc.LoadFromFile(sourcefile1, FileFormat.Docx);
doc.InsertTextFromFile(@"C:\document.docx", FileFormat.Docx);
doc.SaveToFile(@"C:\document.docx", FileFormat.Docx);

//document2
doc.LoadFromFile(sourcefile2, FileFormat.Docx);
doc.InsertTextFromFile(@"C:\document.docx", FileFormat.Docx);
doc.SaveToFile(@"C:\document.docx", FileFormat.Docx);

//document 3
doc.LoadFromFile(sourcefile3, FileFormat.Docx);
doc.InsertTextFromFile(@"C:\document.docx", FileFormat.Docx);
doc.SaveToFile(@"C:\document.docx", FileFormat.Docx);

For example I would like document1 to be on the front page but currently it is put on the last page.

Thank you all

antonoci98
 
Posts: 1
Joined: Tue Jul 26, 2022 9:56 am

Wed Jul 27, 2022 3:07 am

Hi,

Thank you for your inquiry.
Please change your code as below to achieve your need. If you have any questions, please feel free to contact.
Code: Select all
             Document document = new Document();
             document.LoadFromFile(sourcefile1, FileFormat.Docx);
             document.InsertTextFromFile(sourcefile2, FileFormat.Docx);
             document.InsertTextFromFile(sourcefile3, FileFormat.Docx);
             document.SaveToFile(@"merge.docx", FileFormat.Docx);


Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 388
Joined: Mon Mar 07, 2022 2:30 am

Return to Spire.Doc