| View previous topic :: View next topic |
| Author |
Message |
geno Newbie

Joined: 08 Oct 2007 Posts: 3
|
Posted: Mon Oct 08, 2007 1:08 pm Post subject: Copying selected text in document |
|
|
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 |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8984 Location: Lexinton, Kentucky, USA
|
Posted: Tue Oct 09, 2007 5:13 am Post subject: |
|
|
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 |
|
 |
geno Newbie

Joined: 08 Oct 2007 Posts: 3
|
Posted: Wed Oct 10, 2007 4:15 am Post subject: |
|
|
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 |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8984 Location: Lexinton, Kentucky, USA
|
Posted: Wed Oct 10, 2007 7:19 am Post subject: |
|
|
| Your code looks like Java to me and I don't do Java so I can't help. |
|
| Back to top |
|
 |
|
|
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
|