Debian Codegraph @

scripting/examples/beanshell/Writer/InsertText.bsh

raw
1 /*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9 import com.sun.star.uno.UnoRuntime;
10 import com.sun.star.frame.XModel;
11
12 import com.sun.star.text.XTextDocument;
13 import com.sun.star.text.XText;
14 import com.sun.star.text.XTextRange;
15
16 oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
17 if ( oDoc == null )
18 oDoc = XSCRIPTCONTEXT.getDocument();
19
20 String sText = "This text is inserted before the existing text\n" +
21 "Here comes a second line\n";
22
23 xTextDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,oDoc);
24 xText = xTextDoc.getText();
25 xTextRange = xText.getEnd();
26 xTextRange.setString(sText);
27
28 return 0;