HelloWorld.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # HelloWorld python script for the scripting framework
  2. #
  3. # This file is part of the LibreOffice project.
  4. #
  5. # This Source Code Form is subject to the terms of the Mozilla Public
  6. # License, v. 2.0. If a copy of the MPL was not distributed with this
  7. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. #
  9. # This file incorporates work covered by the following license notice:
  10. #
  11. # Licensed to the Apache Software Foundation (ASF) under one or more
  12. # contributor license agreements. See the NOTICE file distributed
  13. # with this work for additional information regarding copyright
  14. # ownership. The ASF licenses this file to you under the Apache
  15. # License, Version 2.0 (the "License"); you may not use this file
  16. # except in compliance with the License. You may obtain a copy of
  17. # the License at http://www.apache.org/licenses/LICENSE-2.0 .
  18. #
  19. def HelloWorldPython():
  20. """Prints the string 'Hello World (in Python)' into the current document.
  21. """
  22. # Get the doc from the scripting context which is made available to all
  23. # scripts.
  24. desktop = XSCRIPTCONTEXT.getDesktop()
  25. model = desktop.getCurrentComponent()
  26. # Check whether there's already an opened document.
  27. # Otherwise, create a new one
  28. if not hasattr(model, "Text"):
  29. model = desktop.loadComponentFromURL(
  30. "private:factory/swriter", "_blank", 0, ())
  31. # get the XText interface
  32. text = model.Text
  33. # create an XTextRange at the end of the document
  34. tRange = text.End
  35. # and set the string
  36. tRange.String = "Hello World (in Python)"
  37. return None
  38. # vim: set shiftwidth=4 softtabstop=4 expandtab: