Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

How to merge word document

365 vues

Publié le

How to merge multiple word documents into 1 master file

  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

How to merge word document

  1. 1. Easily Merge Word DocumentMost of us work with Word document often and sometimes we indeed need merge multiple worddocuments into one master file. To merge word documents into one master file could be veryeasy although Word doesnt have a directly import/export function to do that.Merge Word Documents in Microsoft WordIf we just need merge 2 or 3 word documents, we can easily use Word “insert” function. Open thefirst Word document and just insert the second document at the end of the first word documentcontent by clicking “file” from tool bar “insert” category. Then, repeat this if you want to mergethe third document into the master file. At last, save it. This function enable us select multipleword documents by press “Ctrl” or “Shift” and merge them into one master word file. But the topfile you select will be merged first. So if there is an order that you want to maintain, make sure torename the files first so that the appearance in order in the dialog box.Note: Sometimes when you merge Word documents this way, the formatting does not always thesame as the original. So, you may manually fix it.Merge Word Documents via Spire.DocSpire.Doc is a MS Word component which enables user to perform a wide range of Worddocument processing tasks directly, such as generate, read, write and modify Word document
  2. 2. for .NET and Silverlight. We can use Spire.Doc to merge multiple Word documents into onemaster document via C#/VB.NET. Through this solution, we do not need Microsoft Word installedon our system. Download Spire.Doc here and use the code below to merge Word documents.C# Merge Word Documents:01 private void button1_Click(object sender, EventArgs e)02 {03 string fileName = OpenFile();04 string fileMerge = OpenFile();05 if ((!string.IsNullOrEmpty(fileName)) && (!string.IsNullOrEmpty(fileMerge)))06 {07 //Create word document08 Document document = new Document();09 document.LoadFromFile(fileName,FileFormat.Doc);1011 Document documentMerge = new Document();12 documentMerge.LoadFromFile(fileMerge, FileFormat.Doc);1314 foreach( Section sec in documentMerge.Sections)15 {16 document.Sections.Add(sec.Clone());17 }1819 //Save doc file.20 document.SaveToFile("Sample.doc", FileFormat.Doc);2122 //Launching the MS Word file.23 WordDocViewer("Sample.doc");24 }252627 }2829 private string OpenFile()30 {31 openFileDialog1.Filter = "Word Document (*.doc)|*.doc";32 openFileDialog1.Title = "Choose a document to merage";3334 openFileDialog1.RestoreDirectory = true;35 if (openFileDialog1.ShowDialog() == DialogResult.OK)36 {37 return openFileDialog1.FileName;38 }39
  3. 3. 40 return string.Empty;41 }4243 private void WordDocViewer(string fileName)44 {45 try46 {47 System.Diagnostics.Process.Start(fileName);48 }49 catch { }50 }VB.NET Merge Word Documents:01 Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handlesbutton1.Click02 Dim fileName As String = OpenFile()03 Dim fileMerge As String = OpenFile()04 If ((Not String.IsNullOrEmpty(fileName))) AndAlso ((NotString.IsNullOrEmpty(fileMerge))) Then05 Create word document06 Dim document_Renamed As New Document()07 document_Renamed.LoadFromFile(fileName,FileFormat.Doc)0809 Dim documentMerge As New Document()10 documentMerge.LoadFromFile(fileMerge, FileFormat.Doc)1112 For Each sec As Section In documentMerge.Sections13 document_Renamed.Sections.Add(sec.Clone())14 Next sec1516 Save doc file.17 document_Renamed.SaveToFile("Sample.doc", FileFormat.Doc)1819 Launching the MS Word file.20 WordDocViewer("Sample.doc")21 End If222324 End Sub2526 Private Function OpenFile() As String27 openFileDialog1.Filter = "Word Document (*.doc)|*.doc"28 openFileDialog1.Title = "Choose a document to merage"29
  4. 4. 30 openFileDialog1.RestoreDirectory = True31 If openFileDialog1.ShowDialog() = DialogResult.OK Then32 Return openFileDialog1.FileName33 End If3435 Return String.Empty36 End Function3738 Private Sub WordDocViewer(ByVal fileName As String)39 Try40 Process.Start(fileName)41 Catch42 End Try43 End SubClick here to learn More about Spire.Doc