Skip to content

Instantly share code, notes, and snippets.

How to Remove All Section Breaks in Word using Java. For more details: https://kb.aspose.com/words/java/how-to-remove-all-section-breaks-in-word-using-java/
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");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment