Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8695755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:06:50+00:00 2026-06-13T01:06:50+00:00

If anyone can assist with a method that searches for a string in an

  • 0

If anyone can assist with a method that searches for a string in an open office writer document using the UNO API with Java it would be very helpful. Once it searches for string and finds string can it then(even hidden) move the cursor to that string.

I can then use the below getPageNumber method to return the page number and print that page on headed paper.

Any help much appreciated

public int getNumberOfPages()
{
    XController xController = OODocument.getCurrentDocument().getXFrame().getController();

    XTextViewCursorSupplier supTextViewCursor =
                (XTextViewCursorSupplier) UnoRuntime.queryInterface(
                    XTextViewCursorSupplier.class, xController);

    XTextViewCursor curTextView = supTextViewCursor.getViewCursor();
    XPageCursor curPage =
                (XPageCursor) UnoRuntime.queryInterface(
                    XPageCursor.class, curTextView);
    curPage.jumpToLastPage();
    System.out.println("pages = " + curPage.getPage());
    return curPage.getPage();
}

public int getPageNumber()
{
    XController xController = OODocument.getCurrentDocument().getXFrame().getController();

    XTextViewCursorSupplier supTextViewCursor =
                (XTextViewCursorSupplier) UnoRuntime.queryInterface(
                    XTextViewCursorSupplier.class, xController);

    XTextViewCursor curTextView = supTextViewCursor.getViewCursor();

    XPageCursor curPage =
                (XPageCursor) UnoRuntime.queryInterface(
                    XPageCursor.class, curTextView);

    System.out.println("current page = " + curPage.getPage());
    return curPage.getPage();
}

I know it can be done using a combination of possibly the below

    curTextView.setString("zzzzz");
    curTextView.getText();
    curTextView.gotoRange(arg0, arg1)

or XTextRange.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:06:51+00:00Added an answer on June 13, 2026 at 1:06 am

    Incase anyone needs answer. I worked it out and posted below.

    public int searchPageNumber()
    {
        XController xController = OODocument.getCurrentDocument().getXFrame().getController();
    
        XTextViewCursorSupplier supTextViewCursor =
                    (XTextViewCursorSupplier) UnoRuntime.queryInterface(
                        XTextViewCursorSupplier.class, xController);
    
        XTextViewCursor curTextView = supTextViewCursor.getViewCursor();
    
        // gets the page cursor and assigns the text view cursor to the page
        XPageCursor curPage =
                    (XPageCursor) UnoRuntime.queryInterface(
                        XPageCursor.class, curTextView);
        System.out.println("The current page number is " + curPage.getPage());
    
        // gets the model
        XModel model = xController.getModel();
        // assigns model to the document
        XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, model);
        // Xsearchable so we can search the text
        XSearchable xSearchable = (XSearchable) UnoRuntime.queryInterface(XSearchable.class, xTextDocument); 
        XSearchDescriptor xsd = (XSearchDescriptor) xSearchable.createSearchDescriptor(); 
    
        xsd.setSearchString("zzzzz");
    
        XInterface xfi = (XInterface) xSearchable.findFirst(xsd); 
        if (xfi != null) { 
            XTextRange xStart = (com.sun.star.text.XTextRange) UnoRuntime.queryInterface( 
                    com.sun.star.text.XTextRange.class, xfi); 
    
            curTextView.gotoRange(xStart, false); 
        } 
    
        System.out.println("current page = " + curPage.getPage());
        return curPage.getPage();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone assist me in connecting via Management Studio using the hostname provided by
can anyone assist me in finding the proper formula for quad normalization ? using
Wondering if anyone can assist.. I am adding some jquery to my site, but
Can anyone assist in the following. I have a field notes inside a mysql
Hi everyone I am stack so if anyone can assist in any way it
I have a method that returns a Map(): private Map<String, Catalog> readCatalogFromXml(String xmlFile) {
bit stuck try to achieve something in Jquery and wondered if anyone can assist..
I have a method returning a list of String that need to be sorted.
I think Rails 3.1 is changing the way that errors are raised. Can anyone
Can anyone assist me in getting a function to be called, in this example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.