Development/Create a Hello World LibreOffice extension

In this tutorial we will create a Hello World extension for LibreOffice Calc using LibreOffice Basic language. It is a simple extension to illustrate some of the basic elements of an extension in LibreOffice. The extension will add a button (next to Export as PDF button) to standard toolbar and when it is clicked it shows a dialog with “Hello, World!”. Source code for this tutorial is on github.



Step 1. Creating a folder for our extension
1) Choose a location and create a folder named helloworld.



Step 2. Creating a library for our macro
1) Open LibreOffice Calc. From the Menu Bar, choose Tools > Macros > Organize Macros> LibreOffice Basic.

2) Click Organizer button.



3) Choose Libraries tab, and click New button.



4) Name it HelloWorldLibrary, and click OK. We can see our created library in the Library list.





5) Click Close button to exit from LibreOffice Basic Macro Organizer dialog.

Step 3. Creating the macro
1) Choose My Macros > HelloWorldLibrary >Module1, and click Edit button.



2) Copy macro below and paste into the LibreOffice Basic IDE, then save (Ctrl+S).



Step 4. Exporting our library
1) From the LibreOffice Basic IDE Menu bar, choose Tools > Organize Macros > LibreOffice Basic.

2) Click Organizer button.



3) Select Libraries tab, and choose HelloWorldLibrary from the Library list, then click Export button.



4) Select Export as BASIC library and click OK.



5) Save the library inside our helloworld folder, then click Close to exit from LibreOffice Basic macro organizer and LibreOffice Basic macros. As we see below, the library we exported contains 3 files.



Step 5. Adding a description to our extension
1) Go to folder helloworld, then create a subfolder named pkg-description.



2) Inside pkg-description folder, create a file named pkg-description.en.



3) Paste content below into the file pkg-description.en, click save (Ctrl+S) and close the file.

Hello World LibreOffice extension. Copyright (c) your name 2019.

Step 6. Adding a license
1) Inside folder helloworld, create a subfolder named registration.

2) Inside folder registration, create a file named license.txt, and paste into it the content from this link. Then save (Ctrl+S) and close file.

Step 7. Adding manifest file
1) Inside folder helloworld, create a subfolder named META-INF.

2) Inside folder META-INF, create a file named manifest.xml, and paste into it the content below. Then save (Ctrl+S) and close file.

Step 8. Adding images
1) Inside folder helloworld, create a subfolder named icons.



2) Go to this link and download the 2 images there, save them to the icons folder.

Step 9. Adding the description file
1) Inside folder helloworld, create a file named description.xml.



2) Paste the content below into description.xml file. Then save (Ctrl+S) and close file.

Step 10. Adding a button to toolbar of LibreOffice Calc
1) Inside folder helloworld, create a file named Addons.xcu.

2) Copy this code and paste into the Addons.xcu file. Then save (Ctrl+S) and close file.

Step 12. Packaging the extension
1) Inside helloworld folder, select all files (Ctrl+A).

2) Right-click, and compress to helloworld.zip.



3) Rename helloworld.zip to helloworld.oxt. Now our extension is ready and in the next step we are going to install in LibreOffice Calc.



Step 13. Installing our extension in LibreOffice Calc
1) Open LibreOffice Calc and choose Tools > Extension Manager.

2) Click Add button, and select our extension helloworld.oxt.

3) Accept the Extension Software License Agreement to install the extension.



4) Click Close button, and restart LibreOffice Calc.

Conclusion
In this tutorial, we have created a Hello World extension for LibreOffice Calc. Complete source code can be found on github.