Hi,
We have document with multiple sections.
How I can get in Java section which contain specific bookmark/paragraph?
Thanks Andrei.
Document doc = new Document();
doc.loadFromFile("test.docx");
// Creates a BookmarkNavigator instance to access the bookmark
BookmarksNavigator navigator = new BookmarksNavigator(doc);
// for example, get the bookmark named "test"
navigator.moveToBookmark("test");
// Locate a specific bookmark by bookmark name
Bookmark currentBookmark = navigator.getCurrentBookmark();
// get the owner paragraph
Paragraph ownerParagraph = (Paragraph) currentBookmark.getBookmarkStart().getOwner();
// get the owner body
DocumentObject owner = ownerParagraph.getOwner();
Body body;
// judge the type of the paragraph's owner
if (owner.getDocumentObjectType().equals(DocumentObjectType.Table_Cell)){
TableCell tableCell = (TableCell) owner;
Table table = (Table) tableCell.getOwnerRow().getOwner();
body = table.ownerTextBody();
}else {
body = ownerParagraph.ownerTextBody();
}
// get the owner section
Section ownerSection = (Section) body.getOwner();