[Solved] Use Edit button with python script

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Locked
luofeiyu
Posts: 53
Joined: Thu Sep 14, 2017 2:11 am

[Solved] Use Edit button with python script

Post by luofeiyu »

Install package:

Code: Select all

sudo apt install libreoffice-script-provider-python
Make directory to store python script.

Code: Select all

mkdir -p      .config/libreoffice/4/user/Scripts/python
Edit my first python script:

Code: Select all

cd  .config/libreoffice/4/user/Scripts/python
vim  hello.py
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
Now click buttons on the menu in LibreOffice Calc "Tools > Organize Macros > Python"

I can only run it,can't edit it with this LibreOffice Calc window.
edit.png
edit.png (41.45 KiB) Viewed 7879 times
The "Edit" button can't be clicked to use.
Last edited by luofeiyu on Sat Feb 01, 2025 5:01 am, edited 1 time in total.
LibreOffice 7.4.7.2 on Debian 12
JeJe
Volunteer
Posts: 3064
Joined: Wed Mar 09, 2016 2:40 pm

Re: Why can't click the edit button to edit python script?

Post by JeJe »

Because there's no Python IDE and you have to edit the file yourself with whatever you choose.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
karolus
Volunteer
Posts: 1226
Joined: Sat Jul 02, 2011 9:47 am

Re: Why can't click the edit button to edit python script?

Post by karolus »

Hallo

For managing|organizing python-scripts in context of LO you should install the Extension apso.oxt from here

Your »hello.py« need only the content:

Code: Select all

def HelloWorldPythonCalc():
    oDoc = XSCRIPTCONTEXT.getDocument()
    oSheet =oDoc.getSheets().getByIndex(0)
    oCell = oSheet.getCellByPosition(0,0)
    oCell.String = 'Hello World via Python'
and you may write shorter

Code: Select all

def HelloWorldPythonCalc():
    doc = XSCRIPTCONTEXT.getDocument()
    cell = doc.Sheets[0][0, 0]
    cell.String = 'Hello World via Python'
    
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
Locked