Hi together,

at the moment I try to write a little program that jumps to a bookmark
and inserts some text on this position. For this I consulted Developers
Guide chapter 7.1.2. You can find my whole code on the end of the mail.

Following code always retruns "null". The variable openDocument is an
instance of the class XComponent. Why does it always return null,
although the document is opened correctly and contains two bookmarks
named "Textmarke01" and "Textmarke02"?
-----%<------
// Get bookmark interface from document
XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier)
        UnoRuntime.queryInterface(XBookmarksSupplier.class,
        openDocument);
-----%<-----

Please tell me what I am doing wrong. I use OOo 2.0.4 and Debian Linux.

Greetings, Tobias

-----%<-----
/**
 * Sets the Cursor to a different position.
 *
 * @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 enterStringOnBookmark(String bookmarkName, String text) {
        // Get bookmark interface from document
        XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier)
                UnoRuntime.queryInterface(XBookmarksSupplier.class,
                openDocument);
                
        // 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) {
                if(this.debug == true) System.out.println(e);
        }
                
        // 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);
}

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

Reply via email to