Ask Your Question

Embed Javascript Macro in Document Module [closed]

asked 2017-12-17 13:29:18 +0100

peterwt gravatar image

updated 2020-10-25 00:04:19 +0100

Alex Kemp gravatar image

You can create a Library Module in a Document to hold Basic macros, and using the APSO extension the same for Python macros.

Is it possible to do the same fot Javascript macros and if so how?

EDITED 20/12/17

@Jim K I saw using APSO for Python that the script was put in the Python directory and the additions to manifest.xml.

I noticed looking at the scripts supplied with LO that the beanshell, java, and javascript scripts were in a directory for each script. The directory had the script and a parcel-descriptor.xml file. I wasn't sure if the parcel-descriptor had to be included in the manifest.xml. The example you included shows all i needed, including calling the javascript from Basic.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-10-25 00:04:31.535584


Jim K gravatar imageJim K ( 2017-12-18 22:01:16 +0100 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-12-18 22:27:20 +0100

Jim K gravatar image

updated 2017-12-18 23:33:43 +0100

Here is a working example: embedded_javascript_macro.odt. Unzip to view or change the macro files.

Be sure to put the .js file inside its own module (directory), along with parcel-descriptor.xml. In the attached example, the file is located at embedded_javascript_macro/Scripts/javascript/HelloWorld4/helloworld4.js.

The additional lines to manifest.xml are as follows:

 <manifest:file-entry manifest:full-path="Scripts/javascript/HelloWorld4/helloworld4.js" manifest:media-type=""/>
 <manifest:file-entry manifest:full-path="Scripts/javascript/HelloWorld4/parcel-descriptor.xml" manifest:media-type=""/>
 <manifest:file-entry manifest:full-path="Scripts/javascript/HelloWorld4/" manifest:media-type="application/binary"/>
 <manifest:file-entry manifest:full-path="Scripts/javascript/" manifest:media-type="application/binary"/>
 <manifest:file-entry manifest:full-path="Scripts/" manifest:media-type="application/binary"/>

The following Script URI works, as seen in Call_Macro in the attached document.

LibreOffice needs to be restarted to see JavaScript macros.

As mentioned a few days ago, I do not recommend the built-in LibreOffice JavaScript engine, except perhaps for testing. According to the devguide, JavaScript support is only a prototype, although possibly the documentation is out of date in this regard.

If people are serious about using JavaScript, then an extension similar to APSO could be written. Actually, the majority of the APSO code should work for JavaScript. It would simply require adding extra JavaScript features such as generating parcel-descriptor.xml. Not too hard, if someone were to (unlike me) want to see JavaScript more fully embraced by the LibreOffice community.

edit flag offensive delete link more


Thank you @Jim K, just what I wanted. Please see my edited question.

peterwt gravatar imagepeterwt ( 2017-12-20 23:17:00 +0100 )edit

Question Tools

1 follower


Asked: 2017-12-17 13:29:18 +0100

Seen: 1,180 times

Last updated: Dec 22 '17