Development/Crear una extensión LibreOffice Hola Mundo

    From The Document Foundation Wiki
    This page is a translated version of the page Development/Create a Hello World LibreOffice extension and the translation is 26% complete.
    Other languages:

    En este tutorial crearemos una extensión Hola Mundo para LibreOffice Calc usando el lenguaje LibreOffice Basic. Es una extensión simple para ilustrar algunos de los elementos básicos de una extensión en LibreOffice. La extensión añadirá un botón (en seguida del botón Exportar como PDF) a la barra de herramientas estándar y cuando se haga clic en él muestra un diálogo con el mensaje "Hola, Mundo!". El código fuente de este tutorial esya en github.

    Result.png

    Paso 1. Creando el directorio para nuestra extensión

    1) Seleccione una ubicación y crea un directorio llamado holamundo

    Create a folder.png

    Paso 2. Creando la librería para nuestra macro

    1) Abrir LibreOffice Calc. De la barra de menú, seleccionar, Herramientas > Macros > Organizar Macros> LibreOffice Basic.

    2) Dar clic en el botón de comando Organizar.

    Figure2.1.png

    3) Seleccionar la pestaña Librerias y dar clic en el botón de comando Nuevo.

    Figure2.2.png

    4) Nombrala como LibreriaHolaMundo, y da clic en Aceptar. Podemos ver nuestra librería creada en la lista de librerías.

    Figure2.3.png


    Figure2.4.png

    5) Da clic en el botón de comando Cerrar para salir del cuadro de diálogo Organizar Macros LibreOffice Basic.

    Paso 3. Creando la macro

    1) Selecciona Mis Macros > LibreriaHolaMundo > Modulo1, y da clic en el botón de comando Editar.

    Figure3.1.png

    2) Copia la siguiente macro y pegala dentro del IDE LibreOffice Basic, entonces guardala (CTRL+S).

    Sub HelloWorldMacro
       MsgBox "Hello, World!"
    End Sub

    Figure3.2.png

    Paso 4. Exportando nuestra libreria

    1) En la barra de menús del IDE LibreOffice Basic, seleccione Herramientas > Organizar macros > LibreOffice Basic.

    2) Dar clic en el botón de comando Organizar.

    Figure4.1.png

    3) Seleccionar la pestaña Librerias, y de la lista de librerias seleccionar LibreriaHolaMundo, entonces dar clic en el botón de comando Exportar.

    Figure4.2.png

    4) Seleccionar Exportar como librería Basic y dar clic en Aceptar.

    Figure4.3.png

    5) Guardar la librería dentro de nuestro directorio holamundo, entonces dar clic en Cerrar para salir del Organizador de LibreOffice Basic y las macros LibreOffice Basic. Como vemos en la imagen siguiente, la librería que exportamos contiene tres archivos.

    Figure4.4.png

    Step 5. Adding a description to our extension

    1) Go to folder helloworld, then create a subfolder named pkg-description.

    Figure5.2.png

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

    Figure5.3.png

    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 2024.
    

    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.

    <?xml version="1.0" encoding="UTF-8"?>
    <manifest:manifest>
     <manifest:file-entry manifest:full-path="HelloWorldLibrary/" manifest:media-type="application/vnd.sun.star.basic-library"/>
     <manifest:file-entry manifest:full-path="pkg-description/pkg-description.en" manifest:media-type="application/vnd.sun.star.package-bundle-description;locale=en"/>
     <manifest:file-entry manifest:full-path="Addons.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>
    </manifest:manifest>

    Step 8. Adding images

    1) Inside folder helloworld, create a subfolder named icons.

    Figure8.1.png

    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.

    Figure9.1.png

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

    <?xml version='1.0' encoding='UTF-8'?>
    <description
     xmlns="http://openoffice.org/extensions/description/2006"
     xmlns:dep="http://openoffice.org/extensions/description/2006"
     xmlns:xlink="http://www.w3.org/1999/xlink">
        <identifier value="org.broffice.helloworldmacro"/>
        <icon>
            <default xlink:href="icons/image_42.png" />
        </icon>
        <version value="1.0"/>
        <registration>
            <simple-license  accept-by="admin" default-license-id="ID0" suppress-on-update="true" >
            <license-text xlink:href="registration/license.txt" lang="en" license-id="ID0" />
    	</simple-license>
        </registration>
        <publisher>
            <name xlink:href="mailto:youremail@smt.com">Your Name</name>
        </publisher>
        <display-name>
            <name>Hello World</name>
        </display-name>
    </description>

    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 11. This is our file structure so far

    Figure11.1.png

    Step 12. Packaging the extension

    1) Inside helloworld folder, select all files (Ctrl+A).

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

    Figure12.1.png

    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.

    Figure12.2.png

    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.

    Figure13.1.png

    4) Click Close button, and restart LibreOffice Calc.

    Note: if you get a "!link" warning error message when trying to install the extension, remove the HelloWorldLibrary before trying to install the extension, as LibreOffice cannot install an extension over a macro library of the same name:

    • Open LibreOffice Calc. From the Menu Bar, choose Tools > Macros > Organize Macros> LibreOffice Basic
    • Click the Organizer button, click the Libraries tab, select HelloWorldLibrary from the Library list, then click the Delete button, and confirm that you want to delete the library.
    • You should now be able to install the extension using steps 1 to 4 above.

    Conclusion

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