OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Copying selected text in document

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
geno
Newbie
Newbie


Joined: 08 Oct 2007
Posts: 3

PostPosted: Mon Oct 08, 2007 1:08 pm    Post subject: Copying selected text in document Reply with quote

Hi everyone !

I need help with copying text in document. What i need to do is to find a starting mark and an ending mark in a text, then select from start do end and copy it few times. So in text i would have for example :
Code:

${start:test}
  Inner styled text
${end:test}

And the result would be for example :
Code:

${start:test}
  Inner styled text
${end:test}
${start:test}
  Inner styled text
${end:test}
${start:test}
  Inner styled text
${end:test}

I havent found any solution. What I can do is to copy selected text, but i loose the style of text, since it is copyied by TextRange.getString and then instertString method from cursor. But i need the inner styled text to remain styled.
Got anyone idea how to solve it ? Thanks a lot.
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Tue Oct 09, 2007 5:13 am    Post subject: Reply with quote

This macro will copy selected text X times just below itself. It uses the clipboard and a test case containing bold, underlined and italic text maintained those formats.
http://www.oooforum.org/forum/viewtopic.phtml?t=29291
Back to top
View user's profile Send private message
geno
Newbie
Newbie


Joined: 08 Oct 2007
Posts: 3

PostPosted: Wed Oct 10, 2007 4:15 am    Post subject: Reply with quote

I tried it with this code :

Code:

xOpenSearch.setSearchString("${begin:test}");
       xCloseSearch.setSearchString("${end:test}");
       
       XInterface xi1 = (XInterface)xReplaceable.findFirst(xOpenSearch);
       XTextRange range1 = (XTextRange)UnoRuntime.queryInterface(
                XTextRange.class, xi1);
       XInterface xi2 = (XInterface)xReplaceable.findFirst(xCloseSearch);
       XTextRange range2 = (XTextRange)UnoRuntime.queryInterface(
                XTextRange.class, xi2);
       
       OOoBean oBean = new OOoBean();
       XMultiServiceFactory xFactory = oBean.getMultiServiceFactory();
       
       Object dispatchHelper = xFactory.createInstance("com.sun.star.frame.DispatchHelper");
       XDispatchHelper helper =
             (XDispatchHelper)UnoRuntime.queryInterface(
                   XDispatchHelper.class, dispatchHelper);
       
       
        XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, objectDocumentToStore);
        XController xController = xModel.getCurrentController();
        XFrame xFrame = xController.getFrame();
        XTextViewCursorSupplier xViewCursorSupplier =
            (XTextViewCursorSupplier)UnoRuntime.queryInterface(
                XTextViewCursorSupplier.class, xController);
        XTextViewCursor xViewCursor = xViewCursorSupplier.getViewCursor();
       
        XText xDocumentText = xViewCursor.getText();
        XTextCursor xModelCursor = xDocumentText.createTextCursorByRange(xViewCursor.getStart());
        xViewCursor.gotoRange(range1, false);
         xViewCursor.gotoRange(range2, true);
         System.out.println( xModelCursor.getString() );
         XDispatchProvider xDispatchProvider = (XDispatchProvider)UnoRuntime.queryInterface(XDispatchProvider.class, xFrame);
         helper.executeDispatch(xDispatchProvider, "uno:Copy","", 0, new PropertyValue[]{});
         helper.executeDispatch(xDispatchProvider, "uno:Paste","", 0, new PropertyValue[]{});
         helper.executeDispatch(xDispatchProvider, "uno:Paste","", 0, new PropertyValue[]{});


And
Code:
  oBean.getMultiServiceFactory();
Prints out :
cannot find msvcr70
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Wed Oct 10, 2007 7:19 am    Post subject: Reply with quote

Your code looks like Java to me and I don't do Java so I can't help.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group