令状ing Office Scripts in JavaScript
A 原型 Script Runtime has been developed for JavaScript using the Rhino JavaScript Interpreter from the Mozilla 事業/計画(する). This Runtime 許すs JavaScript scripts to be 遂行する/発効させるd in OpenOffice.org. Unlike the BeanShell and Java Runtimes the JavaScript Runtime is still in 開発 and is not yet fully 機能の, however it is suitable for 実験ing with Office scripting in JavaScript.Some known 制限s of the JavaScript Runtime are:
- 現在/一般に the JavaScript Runtime does support 負担ing of Java classes that are (軍隊を)展開する,配備するd with the JavaScript script.
- The JavaScript Runtime will not 報告(する)/憶測 any errors that occur during the 死刑執行 of the script.
- 現在/一般に there is no support for interactive 開発 of JavaScript scripts.
Contents
取り付け・設備
- Download the JavaScript Runtime UNO 一括
- If you have OpenOffice.org running you should の近くに it.
- Switch to the directory 指名するd program under your OpenOffice.org 取り付け・設備 directory
- Run the 命令(する):
pkgchk <path to your downloaded jsruntime.zip>
Hello World in JavaScript
Here's a JavaScript script that 挿入するs Hello World at the start of an OpenOffice.org Writer 文書:importClass(一括s.com.sun.星/主役にする.uno.UnoRuntime); importClass(一括s.com.sun.星/主役にする.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", 誤った);
The ScriptContext variable above is a 全世界の instance of the XScriptContext type
which is 利用できる to all JavaScript scripts 遂行する/発効させるd by the Scripting
枠組み. See 令状ing Office Scripts
and the XScriptContext type for the methods 利用できる for the XScriptContext type.
Invoking a JavaScript script in OpenOffice.org
You have two choices for making your Hello World script 利用できる for
死刑執行 within OpenOffice.org:
- Using the 命令(する) line 道具s
You can use the CommandLineTools class 利用できる with the Scripting 枠組み to 生成する and (軍隊を)展開する,配備する a Script 小包. To do this with the Hello World script:
- Create a directory called helloworld and create a とじ込み/提出する called helloworld.js in that directory using the code above
- 体制/機構 the 命令(する) line 道具s によれば the 指示/教授/教育s on the 命令(する) Line 道具s page
- To 生成する a script 小包 run the 命令(する):
java CommandLineTools -g -l Rhino=.js
- To (軍隊を)展開する,配備する the 生成するd .sxp とじ込み/提出する:
java CommandLineTools -d <path to helloworld.sxp> <path to your OpenOffice.org>/使用者/Scripts
- Manually (軍隊を)展開する,配備するing your script
- Create a directory called <path to your OpenOffice.org>/使用者/Scripts/rhino/helloworld
- Create a とじ込み/提出する helloworld.js in that directory with the Hello World code
- Create a とじ込み/提出する called 小包-descriptor.xml in that directory with the に引き続いて contents:
<?xml 見解/翻訳/版="1.0" encoding="UTF-8"?> <小包 language="Rhino" xmlns:小包="scripting.dtd"> <script language="Rhino"> <地元の lang="en"> <displayname value="HelloWorld"/> <description>挿入する Hello World in a 文書</description> </地元の> <functionname value="helloworld.js"/> <logicalname value="HelloWorld.Rhino"/> </script> </小包>
Once you have the JavaScript ScriptRuntime 任命する/導入するd and the Hello World script (軍隊を)展開する,配備するd 再開する OpenOffice.org. See the Scripting 枠組み 使用者 Guide for 指示/教授/教育s on how to 貯蔵所d your script to a menu item, 重要な binding or event. To see your script 始める,決める the 場所 to 使用者 and the Language to Rhino in the 割り当てる dialogs.
If you want to change your Hello World script, just edit the helloworld.js とじ込み/提出する in a text editor, save it and rerun the script using your menu, 重要な or event binding. You don't need to 再開する OpenOffice.org or rebind to the script as the Scripting 枠組み reloads the script each time it runs it.