private static void deleteRowByBookmark(Document doc, String bookmarkName) throws Exception {
    // Find the bookmark in the document. Exit if cannot find it.
    Bookmark bookmark = doc.getRange().getBookmarks().get(bookmarkName);
    if (bookmark == null) return;

    // Get the parent row of the bookmark. Exit if the bookmark is not in a row.
    Row row = (Row) bookmark.getBookmarkStart().getAncestor(Row.class);
    if (row == null) return;

    // Remove the row.
    row.remove();
  }
  private static void untangleRowBookmarks(Document doc) throws Exception {
    for (Bookmark bookmark : doc.getRange().getBookmarks()) {
      // Get the parent row of both the bookmark and bookmark end node.
      Row row1 = (Row) bookmark.getBookmarkStart().getAncestor(Row.class);
      Row row2 = (Row) bookmark.getBookmarkEnd().getAncestor(Row.class);

      // If both rows are found okay and the bookmark start and end are contained
      // in adjacent rows, then just move the bookmark end node to the end
      // of the last paragraph in the last cell of the top row.
      if ((row1 != null) && (row2 != null) && (row1.getNextSibling() == row2))
        row1.getLastCell().getLastParagraph().appendChild(bookmark.getBookmarkEnd());
    }
  }