Last active
June 2, 2023 04:20
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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