|
4 | 4 |
|
5 | 5 |
|
6 | 6 | //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")) |
14 | 8 | { |
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++) |
16 | 15 | { |
17 | | - if (CheckTOCEntries((textBody.ChildEntities[i] as WParagraph).Items)) |
| 16 | + if (textBody.ChildEntities[i] is WParagraph) |
18 | 17 | { |
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 | + } |
20 | 22 | } |
21 | 23 | } |
| 24 | + //Saves and closes the Word document instance |
| 25 | + document.Save(@"../../../Output/Result.docx", FormatType.Docx); |
22 | 26 | } |
23 | | -//Saves and closes the Word document instance |
24 | | -document.Save(@"../../../Output/Result.docx", FormatType.Docx); |
25 | | -document.Close(); |
26 | 27 |
|
27 | 28 | /// <summary> |
28 | 29 | /// Iterates into paragraph items. |
|
0 commit comments