SlideShare uma empresa Scribd logo
1 de 4
Easily Merge Word Document

Most of us work with Word document often and sometimes we indeed need merge multiple word
documents into one master file. To merge word documents into one master file could be very
easy although Word doesn't have a directly import/export function to do that.


Merge Word Documents in Microsoft Word
If we just need merge 2 or 3 word documents, we can easily use Word “insert” function. Open the
first Word document and just insert the second document at the end of the first word document
content by clicking “file” from tool bar “insert” category. Then, repeat this if you want to merge
the third document into the master file. At last, save it. This function enable us select multiple
word documents by press “Ctrl” or “Shift” and merge them into one master word file. But the top
file you select will be merged first. So if there is an order that you want to maintain, make sure to
rename 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 the
same as the original. So, you may manually fix it.


Merge Word Documents via Spire.Doc
Spire.Doc is a MS Word component which enables user to perform a wide range of Word
document processing tasks directly, such as generate, read, write and modify Word document
for .NET and Silverlight. We can use Spire.Doc to merge multiple Word documents into one
master document via C#/VB.NET. Through this solution, we do not need Microsoft Word installed
on 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 document
08       Document document = new Document();
09       document.LoadFromFile(fileName,FileFormat.Doc);
10
11       Document documentMerge = new Document();
12       documentMerge.LoadFromFile(fileMerge, FileFormat.Doc);
13
14       foreach( Section sec in documentMerge.Sections)
15       {
16          document.Sections.Add(sec.Clone());
17       }
18
19       //Save doc file.
20       document.SaveToFile("Sample.doc", FileFormat.Doc);
21
22       //Launching the MS Word file.
23       WordDocViewer("Sample.doc");
24    }
25
26
27 }
28
29 private string OpenFile()
30 {
31    openFileDialog1.Filter = "Word Document (*.doc)|*.doc";
32    openFileDialog1.Title = "Choose a document to merage";
33
34    openFileDialog1.RestoreDirectory = true;
35    if (openFileDialog1.ShowDialog() == DialogResult.OK)
36    {
37       return openFileDialog1.FileName;
38    }
39
40       return string.Empty;
41   }
42
43   private void WordDocViewer(string fileName)
44   {
45      try
46      {
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) Handles
button1.Click
02      Dim fileName As String = OpenFile()
03      Dim fileMerge As String = OpenFile()
04                      If    ((Not    String.IsNullOrEmpty(fileName))) AndAlso ((Not
String.IsNullOrEmpty(fileMerge))) Then
05        'Create word document
06        Dim document_Renamed As New Document()
07        document_Renamed.LoadFromFile(fileName,FileFormat.Doc)
08
09        Dim documentMerge As New Document()
10        documentMerge.LoadFromFile(fileMerge, FileFormat.Doc)
11
12        For Each sec As Section In documentMerge.Sections
13           document_Renamed.Sections.Add(sec.Clone())
14        Next sec
15
16        'Save doc file.
17        document_Renamed.SaveToFile("Sample.doc", FileFormat.Doc)
18
19        'Launching the MS Word file.
20        WordDocViewer("Sample.doc")
21      End If
22
23
24 End Sub
25
26 Private Function OpenFile() As String
27      openFileDialog1.Filter = "Word Document (*.doc)|*.doc"
28      openFileDialog1.Title = "Choose a document to merage"
29
30   openFileDialog1.RestoreDirectory = True
31   If openFileDialog1.ShowDialog() = DialogResult.OK Then
32      Return openFileDialog1.FileName
33   End If
34
35   Return String.Empty
36 End Function
37
38 Private Sub WordDocViewer(ByVal fileName As String)
39   Try
40      Process.Start(fileName)
41   Catch
42   End Try
43 End Sub




Click here to learn More about Spire.Doc

Mais conteúdo relacionado

Mais de Chen Stephen (6)

5 ui tips for web apps
5 ui tips for web apps5 ui tips for web apps
5 ui tips for web apps
 
A developer's first impressions for windows 8
A developer's first impressions for windows 8A developer's first impressions for windows 8
A developer's first impressions for windows 8
 
C# excel set excel number style
C# excel   set excel number styleC# excel   set excel number style
C# excel set excel number style
 
C# excel bar chart
C# excel bar chartC# excel bar chart
C# excel bar chart
 
C# insert comments in word
C# insert comments in wordC# insert comments in word
C# insert comments in word
 
Listview to dif
Listview to difListview to dif
Listview to dif
 

Último

CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
Wonjun Hwang
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 

Último (20)

Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهله
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 

How to merge word document

  • 1. Easily Merge Word Document Most of us work with Word document often and sometimes we indeed need merge multiple word documents into one master file. To merge word documents into one master file could be very easy although Word doesn't have a directly import/export function to do that. Merge Word Documents in Microsoft Word If we just need merge 2 or 3 word documents, we can easily use Word “insert” function. Open the first Word document and just insert the second document at the end of the first word document content by clicking “file” from tool bar “insert” category. Then, repeat this if you want to merge the third document into the master file. At last, save it. This function enable us select multiple word documents by press “Ctrl” or “Shift” and merge them into one master word file. But the top file you select will be merged first. So if there is an order that you want to maintain, make sure to rename 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 the same as the original. So, you may manually fix it. Merge Word Documents via Spire.Doc Spire.Doc is a MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document
  • 2. for .NET and Silverlight. We can use Spire.Doc to merge multiple Word documents into one master document via C#/VB.NET. Through this solution, we do not need Microsoft Word installed on 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 document 08 Document document = new Document(); 09 document.LoadFromFile(fileName,FileFormat.Doc); 10 11 Document documentMerge = new Document(); 12 documentMerge.LoadFromFile(fileMerge, FileFormat.Doc); 13 14 foreach( Section sec in documentMerge.Sections) 15 { 16 document.Sections.Add(sec.Clone()); 17 } 18 19 //Save doc file. 20 document.SaveToFile("Sample.doc", FileFormat.Doc); 21 22 //Launching the MS Word file. 23 WordDocViewer("Sample.doc"); 24 } 25 26 27 } 28 29 private string OpenFile() 30 { 31 openFileDialog1.Filter = "Word Document (*.doc)|*.doc"; 32 openFileDialog1.Title = "Choose a document to merage"; 33 34 openFileDialog1.RestoreDirectory = true; 35 if (openFileDialog1.ShowDialog() == DialogResult.OK) 36 { 37 return openFileDialog1.FileName; 38 } 39
  • 3. 40 return string.Empty; 41 } 42 43 private void WordDocViewer(string fileName) 44 { 45 try 46 { 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) Handles button1.Click 02 Dim fileName As String = OpenFile() 03 Dim fileMerge As String = OpenFile() 04 If ((Not String.IsNullOrEmpty(fileName))) AndAlso ((Not String.IsNullOrEmpty(fileMerge))) Then 05 'Create word document 06 Dim document_Renamed As New Document() 07 document_Renamed.LoadFromFile(fileName,FileFormat.Doc) 08 09 Dim documentMerge As New Document() 10 documentMerge.LoadFromFile(fileMerge, FileFormat.Doc) 11 12 For Each sec As Section In documentMerge.Sections 13 document_Renamed.Sections.Add(sec.Clone()) 14 Next sec 15 16 'Save doc file. 17 document_Renamed.SaveToFile("Sample.doc", FileFormat.Doc) 18 19 'Launching the MS Word file. 20 WordDocViewer("Sample.doc") 21 End If 22 23 24 End Sub 25 26 Private Function OpenFile() As String 27 openFileDialog1.Filter = "Word Document (*.doc)|*.doc" 28 openFileDialog1.Title = "Choose a document to merage" 29
  • 4. 30 openFileDialog1.RestoreDirectory = True 31 If openFileDialog1.ShowDialog() = DialogResult.OK Then 32 Return openFileDialog1.FileName 33 End If 34 35 Return String.Empty 36 End Function 37 38 Private Sub WordDocViewer(ByVal fileName As String) 39 Try 40 Process.Start(fileName) 41 Catch 42 End Try 43 End Sub Click here to learn More about Spire.Doc