diff --git a/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Data/DestinationDocument.docx b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Data/DestinationDocument.docx new file mode 100644 index 00000000..3dd4614f Binary files /dev/null and b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Data/DestinationDocument.docx differ diff --git a/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Data/SourceDocument.docx b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Data/SourceDocument.docx new file mode 100644 index 00000000..9c15a336 Binary files /dev/null and b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Data/SourceDocument.docx differ diff --git a/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Import_Headers_and_Footers_from_Another_WordDocument.csproj b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Import_Headers_and_Footers_from_Another_WordDocument.csproj new file mode 100644 index 00000000..c949d700 --- /dev/null +++ b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Import_Headers_and_Footers_from_Another_WordDocument.csproj @@ -0,0 +1,26 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + Always + + + Always + + + Always + + + + diff --git a/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Output/Result.docx b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Output/Result.docx new file mode 100644 index 00000000..1316fdeb Binary files /dev/null and b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Output/Result.docx differ diff --git a/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Output/gitkeep.txt b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Output/gitkeep.txt new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Output/gitkeep.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Program.cs b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Program.cs new file mode 100644 index 00000000..e0d77e41 --- /dev/null +++ b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import-Headers-and-Footers-from-Another-WordDocument/Program.cs @@ -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); + } + } + } + } + } + } + /// + /// Move all the items from one collection to another collection. + /// + /// + /// + private static void MoveItems(EntityCollection childEntities1, EntityCollection childEntities2) + { + for (int i = 0; i < childEntities2.Count; i++) + childEntities1.Add(childEntities2[i].Clone()); + } + } + } + diff --git a/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import_Headers_and_Footers_from_Another_WordDocument.sln b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import_Headers_and_Footers_from_Another_WordDocument.sln new file mode 100644 index 00000000..64e530c5 --- /dev/null +++ b/Sections/Import-Headers-and-Footers-from-Another-WordDocument/.NET/Import_Headers_and_Footers_from_Another_WordDocument.sln @@ -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