Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>
<ItemGroup>
<None Update="Data\SourceDocument.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\DestinationDocument.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;

namespace Import_Headers_and_Footers_from_Another_WordDocument
{
class Program
{
static void Main(string[] args)
{
using (FileStream sourceStreamPath = new FileStream(Path.GetFullPath("Data/SourceDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (FileStream destinationStreamPath = new FileStream(Path.GetFullPath("Data/DestinationDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Opens an source document from file system through constructor of WordDocument class
using (WordDocument document = new WordDocument(sourceStreamPath, FormatType.Automatic))
{
//Opens the destination document
using (WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Docx))
{

WSection section = document.Sections[0] as WSection;
//Move all the items from one collection to another collection
for (int i = 0; i < destinationDocument.Sections.Count; i++)
{
MoveItems(destinationDocument.Sections[i].HeadersFooters.EvenHeader.ChildEntities, section.HeadersFooters.Header.ChildEntities);
MoveItems(destinationDocument.Sections[i].HeadersFooters.EvenFooter.ChildEntities, section.HeadersFooters.Footer.ChildEntities);
MoveItems(destinationDocument.Sections[i].HeadersFooters.OddHeader.ChildEntities, section.HeadersFooters.Header.ChildEntities);
MoveItems(destinationDocument.Sections[i].HeadersFooters.OddFooter.ChildEntities, section.HeadersFooters.Footer.ChildEntities);
MoveItems(destinationDocument.Sections[i].HeadersFooters.FirstPageHeader.ChildEntities, section.HeadersFooters.Header.ChildEntities);
MoveItems(destinationDocument.Sections[i].HeadersFooters.FirstPageFooter.ChildEntities, section.HeadersFooters.Footer.ChildEntities);
destinationDocument.Sections[i].PageSetup.DifferentOddAndEvenPages = section.PageSetup.DifferentOddAndEvenPages;
destinationDocument.Sections[i].PageSetup.DifferentFirstPage = section.PageSetup.DifferentFirstPage;
}
using (FileStream outputStream = new FileStream(Path.GetFullPath("Output/Result.docx"), FileMode.Create))
{
destinationDocument.Save(outputStream, FormatType.Docx);
}
}
}
}
}
}
/// <summary>
/// Move all the items from one collection to another collection.
/// </summary>
/// <param name="childEntities1"></param>
/// <param name="childEntities2"></param>
private static void MoveItems(EntityCollection childEntities1, EntityCollection childEntities2)
{
for (int i = 0; i < childEntities2.Count; i++)
childEntities1.Add(childEntities2[i].Clone());
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.37216.2 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Import_Headers_and_Footers_from_Another_WordDocument", "Import-Headers-and-Footers-from-Another-WordDocument\Import_Headers_and_Footers_from_Another_WordDocument.csproj", "{578DCB93-2F8F-DBAB-C1CE-AB9532F653E6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{578DCB93-2F8F-DBAB-C1CE-AB9532F653E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{578DCB93-2F8F-DBAB-C1CE-AB9532F653E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{578DCB93-2F8F-DBAB-C1CE-AB9532F653E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{578DCB93-2F8F-DBAB-C1CE-AB9532F653E6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {62F21DF8-8D09-4911-83B2-3A4008C795A3}
EndGlobalSection
EndGlobal
Loading