SlideShare una empresa de 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

Más contenido relacionado

Más 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

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

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