- If you have OpenOffice.org running you should close it.
- Switch to the directory named program under your OpenOffice.org installation directory
- Run the command:
pkgchk <path to your downloaded jsruntime.zip>
importClass(Packages.com.sun.star.uno.UnoRuntime); importClass(Packages.com.sun.star.text.XTextDocument); var oModel = ScriptContext.getDocument(); var oTextdoc = UnoRuntime.queryInterface(XTextDocument, oModel); var oText = oTextdoc.getText(); var oCursor = oText.createTextCursor(); oText.insertString(oCursor, "Hello World", false);
The ScriptContext variable above is a global instance of the XScriptContext type
Framework. See Writing Office Scripts
and the XScriptContext type for the methods available for the XScriptContext type.
You have two choices for making your Hello World script available for
execution within OpenOffice.org:
- Using the command line tools
You can use the CommandLineTools class available with the Scripting Framework to generate and deploy a Script Parcel. To do this with the Hello World script:
- Create a directory called helloworld and create a file called helloworld.js in that directory using the code above
- Setup the command line tools according to the instructions on the Command Line Tools page
- To generate a script parcel run the command:
java CommandLineTools -g -l Rhino=.js
- To deploy the generated .sxp file:
java CommandLineTools -d <path to helloworld.sxp> <path to your OpenOffice.org>/user/Scripts
- Manually deploying your script
- Create a directory called <path to your OpenOffice.org>/user/Scripts/rhino/helloworld
- Create a file helloworld.js in that directory with the Hello World code
- Create a file called parcel-descriptor.xml in that directory with the following contents:
<?xml version="1.0" encoding="UTF-8"?> <parcel language="Rhino" xmlns:parcel="scripting.dtd"> <script language="Rhino"> <locale lang="en"> <displayname value="HelloWorld"/> <description>Insert Hello World in a document</description> </locale> <functionname value="helloworld.js"/> <logicalname value="HelloWorld.Rhino"/> </script> </parcel>
If you want to change your Hello World script, just edit the helloworld.js file in a text editor, save it and rerun the script using your menu, key or event binding. You don't need to restart OpenOffice.org or rebind to the script as the Scripting Framework reloads the script each time it runs it.