Skip to content

Commit 7e7812e

Browse files
Changed the code snippet that add a no break at first section
1 parent 99a31d7 commit 7e7812e

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.Core" 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>
Lines changed: 1 addition & 0 deletions
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+
4+
//Create a list and add the paths of the source Word documents to it.
5+
List<string> sourceFileNames = new List<string>();
6+
sourceFileNames.Add("Data/Addressblock.docx");
7+
sourceFileNames.Add("Data/Salutation.docx");
8+
sourceFileNames.Add("Data/Greetings.docx");
9+
10+
//Get the absolute path of the destination Word document.
11+
string destinationFileName = Path.GetFullPath(@"Data/Title.docx");
12+
using (FileStream destinationStream = new FileStream(destinationFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
13+
{
14+
//Open the destination document.
15+
using (WordDocument destinationDocument = new WordDocument(destinationStream, FormatType.Automatic))
16+
{
17+
ImportOtherDocuments(sourceFileNames, destinationDocument);
18+
//Save 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+
}
23+
}
24+
}
25+
26+
/// <summary>
27+
/// Import content from multiple source Word documents into a destination document.
28+
/// </summary>
29+
void ImportOtherDocuments(List<string> sourceFiles, WordDocument destinationDocument)
30+
{
31+
//Iterate through each source document from the list.
32+
foreach (string sourceFileName in sourceFiles)
33+
{
34+
using (FileStream sourceStream = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
35+
{
36+
//Open the source document.
37+
using (WordDocument sourceDocument = new WordDocument(sourceStream, FormatType.Automatic))
38+
{
39+
//Set the break-code of First section of source document as NoBreak to avoid imported from a new page.
40+
sourceDocument.Sections[0].BreakCode = SectionBreakCode.NoBreak;
41+
//Import the contents of source document at the end of destination document.
42+
destinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles);
43+
}
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)