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

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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 - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 

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