Page 1 of 1

[Solved] Use Edit button with python script

Posted: Fri Jan 31, 2025 3:53 am
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 8527 times
The "Edit" button can't be clicked to use.

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

Posted: Fri Jan 31, 2025 10:52 am
by JeJe
Because there's no Python IDE and you have to edit the file yourself with whatever you choose.

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

Posted: Fri Jan 31, 2025 1:12 pm
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'