Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.
Wed Apr 05, 2017 3:42 pm
I have this function , I am using it to merge Two Word Documents , How I can edit it to merge 3 ,4 and more Documents??
I am using the library Spire.Doc
What I have tried:
- Code: Select all
public void merge(string doc1,string doc2 , string doc3)
{
//Load Document1 and Document2 and Document3
Document DocOne = new Document();
DocOne.LoadFromFile(doc1, FileFormat.Docx);
Document DocTwo = new Document();
DocTwo.LoadFromFile(doc2, FileFormat.Docx);
Document DocThree = new Document();
DocOne.LoadFromFile(doc3, FileFormat.Docx);
//Merge
foreach (Section sec in DocTwo.Sections )
{
DocOne.Sections.Add(sec.Clone());
}
//Save and Launch
object filename = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Merge.docx";
DocOne.SaveToFile(filename.ToString(), FileFormat.Docx);
System.Diagnostics.Process.Start(filename.ToString());
}//merge
-
rawanmansour62@hotmail.com
-
- Posts: 2
- Joined: Wed Apr 05, 2017 3:29 pm
Thu Apr 06, 2017 2:06 am
Hi,
Thanks for your inquiry.
Here is sample code for your reference.
- Code: Select all
public static void MergeFiles(List<string> mergeFiles)
{
Document doc0 = new Document(mergeFiles[0]);
for (int i = 1; i < mergeFiles.Count; i++)
{
Document doc1 = new Document(mergeFiles[i]);
foreach (Section sec in doc1.Sections)
{
doc0.Sections.Add(sec.Clone());
}
}
doc0.SaveToFile("Result.docx", FileFormat.Docx);
}
If you have any question, please let me know.
Sincerely
Betsy
E-iceblue support team
-
Betsy.jiang
-
- Posts: 3099
- Joined: Tue Sep 06, 2016 8:30 am
Thu Apr 06, 2017 7:22 am
Hi,
Thanks for your feedback.
If you have any question, please feel free to contact us
.
Sincerely,
Betsy
E-iceblue support team
-
Betsy.jiang
-
- Posts: 3099
- Joined: Tue Sep 06, 2016 8:30 am