I've the following test document which contains a simple table and two bookmarks. The 1st bookmark encloses row 1 and 2 and the 2nd bookmark encloses row 3 and 4.
Now have a look on the following simple test code:
- Code: Select all
public static void main(String[] args) {
Document document = new Document();
document.loadFromFile("Test.docx");
Bookmark bookmark1 = document.getBookmarks().get("B1");
int rowIndexStart1 = getTableCell(bookmark1.getBookmarkStart()).getOwnerRow().getRowIndex();
int rowIndexEnd1 = getTableCell(bookmark1.getBookmarkEnd()).getOwnerRow().getRowIndex();
System.out.println("Bookmark 1 encloses rows " + rowIndexStart1 + " to " + rowIndexEnd1);
Bookmark bookmark2 = document.getBookmarks().get("B2");
int rowIndexStart2 = getTableCell(bookmark2.getBookmarkStart()).getOwnerRow().getRowIndex();
int rowIndexEnd2 = getTableCell(bookmark2.getBookmarkEnd()).getOwnerRow().getRowIndex();
System.out.println("Bookmark 2 encloses rows " + rowIndexStart2 + " to " + rowIndexEnd2);
}
public static TableCell getTableCell(final DocumentObject documentObject) {
DocumentObject parent = documentObject.getOwner();
while (parent != null && !(parent instanceof TableCell)) {
parent = parent.getOwner();
}
return (TableCell) parent;
}
I expect the following output:
Bookmark 1 encloses rows 0 to 1
Bookmark 2 encloses rows 2 to 3
but I actually get the following output:
Bookmark 1 encloses rows 0 to 2
Bookmark 2 encloses rows 2 to 3
So the bookmarks seem overlapping but they aren't. I consider this as a bug and ask you to have a closer look to it.
Kind regards,
Marcus