InsertText.bsh 882 B

12345678910111213141516171819202122232425262728
  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. import com.sun.star.uno.UnoRuntime;
  9. import com.sun.star.frame.XModel;
  10. import com.sun.star.text.XTextDocument;
  11. import com.sun.star.text.XText;
  12. import com.sun.star.text.XTextRange;
  13. oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
  14. if ( oDoc == null )
  15. oDoc = XSCRIPTCONTEXT.getDocument();
  16. String sText = "This text is inserted before the existing text\n" +
  17. "Here comes a second line\n";
  18. xTextDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,oDoc);
  19. xText = xTextDoc.getText();
  20. xTextRange = xText.getEnd();
  21. xTextRange.setString(sText);
  22. return 0;