Skip to content

Commit 70a87b6

Browse files
author
Konduru Keerthi Konduru Ravichandra Raju
committed
Remove header and footer
1 parent 00b0e79 commit 70a87b6

File tree

1 file changed

+28
-37
lines changed
  • Sections/Remove-headers-footers-in-section/.NET/Remove-headers-footers-in-section

1 file changed

+28
-37
lines changed
Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,39 @@
11
using Syncfusion.DocIO.DLS;
22
using Syncfusion.DocIO;
33

4-
namespace Remove_headers_footers_in_section
4+
//Open an existing document
5+
using (FileStream inputStream = new FileStream(@"../../../Data/Template.docx", FileMode.Open, FileAccess.Read))
56
{
6-
internal class Program
7+
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
78
{
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];
9+
//Get the section
10+
WSection section = document.Sections[2];
1711

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();
12+
//Remove the first page header
13+
section.HeadersFooters.FirstPageHeader.ChildEntities.Clear();
14+
section.HeadersFooters.FirstPageHeader.AddParagraph();
15+
//Remove the first page footer
16+
section.HeadersFooters.FirstPageFooter.ChildEntities.Clear();
17+
section.HeadersFooters.FirstPageFooter.AddParagraph();
2418

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();
19+
//Remove the odd header
20+
section.HeadersFooters.OddHeader.ChildEntities.Clear();
21+
section.HeadersFooters.OddHeader.AddParagraph();
22+
//Remove the odd footer
23+
section.HeadersFooters.OddFooter.ChildEntities.Clear();
24+
section.HeadersFooters.OddFooter.AddParagraph();
3125

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();
26+
//Remove the even header
27+
section.HeadersFooters.EvenHeader.ChildEntities.Clear();
28+
section.HeadersFooters.EvenHeader.AddParagraph();
29+
//Remove the even footer
30+
section.HeadersFooters.EvenFooter.ChildEntities.Clear();
31+
section.HeadersFooters.EvenFooter.AddParagraph();
3832

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-
}
33+
//Save the Word document
34+
using (FileStream outputStream = new FileStream(@"../../../Output.docx", FileMode.Create, FileAccess.Write))
35+
{
36+
document.Save(outputStream, FormatType.Docx);
4637
}
4738
}
48-
}
39+
}

0 commit comments

Comments
 (0)