Delete a section break but not its content

Hi
I’d like to delete a section break in a word document, but not the text which is in this section. Is it possible to do that with Aspose.Words for Java ?
Thank you in advance.

Hi Anne,
Thanks for your inquiry.
Yes, you can use Aspose.Words for Java to add content of a section to another section in the document, which in turn will enable you to delete section break(s) and add content of the section(s) under consideration to another one. You can get all the sections using getSections method of Document class, then use appendContent method of Section class to append content of any other section to it, and finally remove the section from sections array of the document. Here is the code snippet which appends all sections contents to the first section and removes all sections except the first one, might help you:

Document doc = new Document(csInputFilePath);
Section[] cSections = doc.getSections().toArray();
// Append content of all section to the first section
for (int i = 0; i < cSections.length; i++)
{
    Section sect = cSections[i];
    if (!sect.equals(doc.getFirstSection()))
    {
        doc.getFirstSection().appendContent(sect);
    }
}

// Remove all sections but first
while (!doc.getLastSection().equals(doc.getFirstSection()))
{
    doc.getLastSection().remove();
}
// Save document
doc.save(csOutputFilePath);

Additionally, you can also have a look here to explore sections and their usage in Aspose.Words for Java. Hope this helps. Please do let us know if you have any more queries.
Best Regards,
Muhammad Iqbal
Support Developer
Aspose Sialkot Team
Aspose - Your File Format Experts
Keep in touch! We’re on Twitter and Facebook

Thanks a lot. It works great.