Skip to content

Commit 3ecfb37

Browse files
committed
Modified the code snippet
1 parent c5e355e commit 3ecfb37

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

  • Word-document/Insert-PageBreak-Before-Heading-Paragraphs/.NET/Insert-PageBreak-Before-Heading-Paragraphs

Word-document/Insert-PageBreak-Before-Heading-Paragraphs/.NET/Insert-PageBreak-Before-Heading-Paragraphs/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public static void Main(string[] args)
1010
WordDocument document = new WordDocument(Path.GetFullPath("Data/Input.docx"));
1111
// Find all paragraphs with the style "Heading 1"
1212
List<Entity> entities = document.FindAllItemsByProperty(EntityType.Paragraph, "StyleName", "Heading 1");
13-
1413
if (entities == null)
1514
{
1615
Console.WriteLine("No paragraphs with the style 'Heading 1' found.");
@@ -19,7 +18,6 @@ public static void Main(string[] args)
1918
{
2019
foreach (Entity entity in entities)
2120
{
22-
// Check if the entity is a paragraph
2321
WParagraph paragraph = entity as WParagraph;
2422
// Get the index of the current paragraph in its parent text body
2523
int index = paragraph.OwnerTextBody.ChildEntities.IndexOf(paragraph);
@@ -35,7 +33,7 @@ public static void Main(string[] args)
3533
// Get the last item in the previous paragraph
3634
ParagraphItem lastItem = previousParagraph.ChildEntities[previousParagraph.ChildEntities.Count - 1] as ParagraphItem;
3735
// Enable the boolean if the last item is a page break
38-
if (lastItem != null && lastItem is Break && (lastItem as Break).BreakType == BreakType.PageBreak)
36+
if (lastItem is Break && (lastItem as Break).BreakType == BreakType.PageBreak)
3937
hasPageBreak = true;
4038
}
4139
// If no page break is found, insert the page break before the current paragraph

0 commit comments

Comments
 (0)