Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. aspose-com-kb revised this gist Jun 2, 2023. No changes.
  2. aspose-com-kb created this gist May 31, 2023.
    24 changes: 24 additions & 0 deletions How to Remove All Section Breaks in Word using Java.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    import com.aspose.words.*;
    public class Main {
    public static void main(String[] args) throws Exception // Eliminate Sections breaks in Java
    {
    // Set the license
    new License().setLicense("Aspose.Total.lic");

    // Load the DOCX
    Document docWithSec = new Document("DocWithSections.docx");

    // Run the loop for the sections
    for (int iCounter = docWithSec.getSections().getCount() - 2; iCounter >= 0; iCounter--)
    {
    // Append the contents
    docWithSec.getLastSection().prependContent(docWithSec.getSections().get(iCounter));

    // Remove the current section
    docWithSec.getSections().get(iCounter).remove();
    }
    docWithSec.save("FinalFile.docx");

    System.out.println("Done");
    }
    }