Ceci est une ancienne révision du document !
Table des matières
Les macros avec LibreOffice
Version LibreOffice : 6.4.1
OS: Ubuntu 23.10
Avec LibreOffice Calc, il est possible d'éxécuter des macros, un ensemble de fonctions qui permet de manipuler et d'effectuer des opérations dans un ou plusieurs fichiers LibreOffice.
Les langages de programmation disponibles sont le BASIC, Python, JavaScript et BeanShell. Par defaut, seul BASIC est disponible.
Python
Résumé de l'article: https://www.debugpoint.com/first-python-macro-libreoffice/
Pour utiliser Python pour programmer des macros, il faut installer le script:
sudo apt install libreoffice-script-provider-python
Avec BASIC l'éditeur de code est fourni dans LibreOffice. Pour Python il faudrat utiliser un éditeur extérieur type Thonny
Les fichiers de macros sont détéctés par libre_office lorsqu'ils sont dans le dossier qu'il faut créé:
~/.config/libreoffice/4/user/Scripts/python
La macro Hello Wolrd:
import uno def HelloWorldPythonCalc(): oDoc = XSCRIPTCONTEXT.getDocument() oSheet =oDoc.getSheets().getByIndex(0) oCell = oSheet.getCellByPosition(0,0) oCell.String = 'Hello World via Python' return None
Pour éxécuter la macro:
Si le bouton 'Run' ou 'Éxécuter' est grisé, la syntaxe du code est probablement erroné quelque part. Éxécuter la macro dans l'éditeur Python aidera à détecter l'erreur.
Sources et resources
https://api.libreoffice.org/
https://extensions.libreoffice.org/en/extensions/show/apso-alternative-script-organizer-for-python
https://www.debugpoint.com/first-python-macro-libreoffice/
https://wiki.documentfoundation.org/images/4/44/CG6212FR-Macros.pdf
https://wiki.documentfoundation.org/Macros/Python_Design_Guide
https://wiki.documentfoundation.org/Macros/Python_Guide/My_first_macro
https://help.libreoffice.org/latest/fr/text/sbasic/python/python_programming.html
https://help.libreoffice.org/latest/fr/text/sbasic/python/python_ide.html
https://help.libreoffice.org/latest/fr/text/sbasic/python/python_locations.html
https://extensions.libreoffice.org/en/extensions/show/41700
https://python-ooo-dev-tools.readthedocs.io/en/main/index.html
https://www.youtube.com/watch?v=pHlLdyJz2sE
https://www.youtube.com/watch?v=d5Mga1TibJc