Hi Joan,

> But now, how I manage to write something in that position?

I use the method below to paste text on the position of a bookmark. You
will also find the answer to you question in the developers guide.

Greetings, Tobias

-----%<-----
/**
 * Sets the Cursor to a bookmark position and replaces text on this
position.
 * If the bookmark contains more than at least one char, the text is
 * replaced. Otherwise the text is just inserted.
 *
 * @param bookmarkName Name of the Bookmark the cursor should jump to.
 * @param text The text that is going to be insertet on bookmark position
 */
public void replaceStringOnBookmark(String bookmarkName, String text) {
try {
        // Get text document out the the general document
        XTextDocument xTextDocument = (XTextDocument)
                UnoRuntime.queryInterface(XTextDocument.class, xComponent);
        if (xTextDocument == null) {
                if (debug > 0)
                        System.out.println("Document is not a Text Document." + 
" Aborting.");
                return;
        }
                        
        // Get bookmark interface from document
        XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier)
                UnoRuntime.queryInterface(XBookmarksSupplier.class, xComponent);
                        
        // Accessing the Bookmarks collection of the document
        XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks();
                        
        // Find the Bookmark specified in bookmarkName
        Object bookmark = null;
        try {
                bookmark = xNamedBookmarks.getByName(bookmarkName);
        } catch (Exception e) {
                return;
        }
        if (bookmark == null) {
                return;
        }
                        
        // Query for XTextContext, the content of the Bookmark
        XTextContent xBookmarkContent = (XTextContent)
                        UnoRuntime.queryInterface(XTextContent.class, bookmark);
                        
        // Get the anchor of the bookmark (its XTextRange)
        XTextRange xBookmarkRange = xBookmarkContent.getAnchor();
                        
        // Set string at bookmark position
        xBookmarkRange.setString(text);
} catch (Exception e) {
        return;
}
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to