Skip to content

Commit 765cd19

Browse files
author
Konduru Keerthi Konduru Ravichandra Raju
committed
Remove headers and footers
1 parent 7adba4c commit 765cd19

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-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.10.34928.147
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Remove-headers-footers-in-section", "Remove-headers-footers-in-section\Remove-headers-footers-in-section.csproj", "{A04CC236-7FAF-49D9-ACBD-F0C4BFBFD137}"
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+
{A04CC236-7FAF-49D9-ACBD-F0C4BFBFD137}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{A04CC236-7FAF-49D9-ACBD-F0C4BFBFD137}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{A04CC236-7FAF-49D9-ACBD-F0C4BFBFD137}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{A04CC236-7FAF-49D9-ACBD-F0C4BFBFD137}.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 = {8B6C3119-165C-4D36-B570-D2A7C0ABCF23}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
4+
namespace Remove_headers_footers_in_section
5+
{
6+
internal class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
//Open an existing document
11+
using (FileStream inputStream = new FileStream(@"../../../Data/Template.docx", FileMode.Open, FileAccess.Read))
12+
{
13+
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
14+
{
15+
//Get the section
16+
WSection section = document.Sections[2];
17+
18+
//Remove the first page header
19+
section.HeadersFooters.FirstPageHeader.ChildEntities.Clear();
20+
section.HeadersFooters.FirstPageHeader.AddParagraph();
21+
//Remove the first page footer
22+
section.HeadersFooters.FirstPageFooter.ChildEntities.Clear();
23+
section.HeadersFooters.FirstPageFooter.AddParagraph();
24+
25+
//Remove the odd header
26+
section.HeadersFooters.OddHeader.ChildEntities.Clear();
27+
section.HeadersFooters.OddHeader.AddParagraph();
28+
//Remove the odd footer
29+
section.HeadersFooters.OddFooter.ChildEntities.Clear();
30+
section.HeadersFooters.OddFooter.AddParagraph();
31+
32+
//Remove the even header
33+
section.HeadersFooters.EvenHeader.ChildEntities.Clear();
34+
section.HeadersFooters.EvenHeader.AddParagraph();
35+
//Remove the even footer
36+
section.HeadersFooters.EvenFooter.ChildEntities.Clear();
37+
section.HeadersFooters.EvenFooter.AddParagraph();
38+
39+
//Save the Word document
40+
using (FileStream outputStream = new FileStream(@"../../../Output.docx", FileMode.Create, FileAccess.Write))
41+
{
42+
document.Save(outputStream, FormatType.Docx);
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Remove_headers_footers_in_section</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+
</Project>

0 commit comments

Comments
 (0)