Skip to content

Commit a000750

Browse files
Added
1 parent 2985133 commit a000750

File tree

8 files changed

+105
-0
lines changed

8 files changed

+105
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34322.80
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Merge–multiple-Word-files-in-same-page", "Merge–multiple-Word-files-in-same-page\Merge–multiple-Word-files-in-same-page.csproj", "{C790F761-62BA-49E1-8FF6-E15165CB08C1}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{C790F761-62BA-49E1-8FF6-E15165CB08C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C790F761-62BA-49E1-8FF6-E15165CB08C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C790F761-62BA-49E1-8FF6-E15165CB08C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C790F761-62BA-49E1-8FF6-E15165CB08C1}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {F533289D-7351-4DA3-96EE-B9C18CA8DCDD}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Merge_multiple_Word_files_in_same_page</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.NET" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Addressblock.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Data\Greetings.docx">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
<None Update="Data\Salutation.docx">
23+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
24+
</None>
25+
<None Update="Data\Title.docx">
26+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
27+
</None>
28+
<None Update="Output\.gitkeep">
29+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
30+
</None>
31+
</ItemGroup>
32+
33+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using System.Runtime.Serialization;
4+
5+
//Get the list of source document to be imported
6+
List<string> sourceFileNames = new List<string>();
7+
sourceFileNames.Add("Data/Addressblock.docx");
8+
sourceFileNames.Add("Data/Salutation.docx");
9+
sourceFileNames.Add("Data/Greetings.docx");
10+
11+
string destinationFileName = Path.GetFullPath(@"Data/Title.docx");
12+
using (FileStream destinationStreamPath = new FileStream(destinationFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
13+
{
14+
//Opens the destination document
15+
using (WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Automatic))
16+
{
17+
ImportOtherDocuments(sourceFileNames, destinationDocument);
18+
//Saves and closes the destination document
19+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.Write))
20+
{
21+
destinationDocument.Save(outputStream, FormatType.Docx);
22+
destinationDocument.Close();
23+
}
24+
}
25+
}
26+
27+
void ImportOtherDocuments(List<string> sourceFiles, WordDocument destinationDocument)
28+
{
29+
//Iterate through each source document from the list
30+
foreach (string sourceFileName in sourceFiles)
31+
{
32+
//Open source document
33+
using (FileStream sourceStreamPath = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
34+
{
35+
using (WordDocument document = new WordDocument(sourceStreamPath, FormatType.Automatic))
36+
{
37+
//Sets the break-code of First section of source document as NoBreak to avoid imported from a new page
38+
document.LastSection.BreakCode = SectionBreakCode.NoBreak;
39+
//Imports the contents of source document at the end of destination document
40+
destinationDocument.ImportContent(document, ImportOptions.UseDestinationStyles);
41+
//Close the document.
42+
document.Close();
43+
}
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)