Skip to content

Commit 5221fe5

Browse files
committed
Added changes
1 parent 4dc64f0 commit 5221fe5

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

  • Table-Of-Contents/Apply-line-spacing-to-TOC-entries/.NET/Apply-line-spacing-to-TOC-entries

‎Table-Of-Contents/Apply-line-spacing-to-TOC-entries/.NET/Apply-line-spacing-to-TOC-entries/Program.cs‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@
44

55

66
//Creates a new Word document
7-
WordDocument document = new WordDocument(@"../../../Data/Template.docx");
8-
//Updates the table of contents
9-
document.UpdateTableOfContents();
10-
TableOfContent tableOfContents = (document.Sections[0].Paragraphs[0] as WParagraph).ChildEntities[0] as TableOfContent;
11-
//Iterate the toc section and apply line spacing.
12-
WTextBody textBody = tableOfContents.OwnerParagraph.OwnerTextBody;
13-
for (int i = 0; i < textBody.ChildEntities.Count; i++)
7+
using (WordDocument document = new WordDocument(@"../../../Data/Template.docx"))
148
{
15-
if (textBody.ChildEntities[i] is WParagraph)
9+
//Updates the table of contents
10+
document.UpdateTableOfContents();
11+
TableOfContent tableOfContents = (document.Sections[0].Paragraphs[0] as WParagraph).ChildEntities[0] as TableOfContent;
12+
//Iterate the toc section and apply line spacing.
13+
WTextBody textBody = tableOfContents.OwnerParagraph.OwnerTextBody;
14+
for (int i = 0; i < textBody.ChildEntities.Count; i++)
1615
{
17-
if (CheckTOCEntries((textBody.ChildEntities[i] as WParagraph).Items))
16+
if (textBody.ChildEntities[i] is WParagraph)
1817
{
19-
(textBody.ChildEntities[i] as WParagraph).ParagraphFormat.LineSpacing = 30;
18+
if (CheckTOCEntries((textBody.ChildEntities[i] as WParagraph).Items))
19+
{
20+
(textBody.ChildEntities[i] as WParagraph).ParagraphFormat.LineSpacing = 30;
21+
}
2022
}
2123
}
24+
//Saves and closes the Word document instance
25+
document.Save(@"../../../Output/Result.docx", FormatType.Docx);
2226
}
23-
//Saves and closes the Word document instance
24-
document.Save(@"../../../Output/Result.docx", FormatType.Docx);
25-
document.Close();
2627

2728
/// <summary>
2829
/// Iterates into paragraph items.

0 commit comments

Comments
 (0)