0

i'm trying to merge multiple word document into one document using spire.doc, 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

Clemens
  • 123,504
  • 12
  • 155
  • 268

1 Answers1

0

You can use the following code to achieve your requirement:

Document doc = new Document();
doc.LoadFromFile("file1.docx");

string[] files = new string[] {"file2.docx", "file3.docx" };

//Insert contents from multiple files into file1.docx
foreach (string file in files)
{
    doc.InsertTextFromFile(file, FileFormat.Docx);
}

//Save the result file
doc.SaveToFile("merge.docx", FileFormat.Docx);
Dheeraj Malik
  • 703
  • 1
  • 4
  • 8