I am using LibreOffice 25.2 (latest), but it has happened before.
I am running the script through Macros menu or through a button click event.(it happens with or without using APSO)
So you have that code as a .py somewhere in your profile, or in a document?
Yes, Exactly!
…
or
?
I’m confused.
py.ods (8.9 KB)
Aha, I see the problem with the document that I had to create myself. You may want to file a bug report.
Sorry I understood profile as LibreOffice python folder or document as a file embedded with APSO in the document.
Both of them are correct. It happens in any way.
I attach a project with the script inserted in the document with APSO.
example.ods (15.3 KB)
EDIT: OK, I saw your edit! So it may be a bug then?
Yes, it’s (or at least may be) a bug. SF has _FindModuleFromMethod
function, which calls getChildNodes
from macro organizer; and that tries to load Java, because indeed one of its nodes is Java. But the function explicitly only wants Basic.
It seems like they could use ScriptProviderForBasic
service instead.
I cannot reproduce neither with
edit: yes, with disabled Java I can reproduce!
Version: 25.8.0.0.alpha0+ (AARCH64) / LibreOffice Community
Build ID: 186e997c559c7e5d4b9462f9b4be6a935cdd04cd
CPU threads: 4; OS: Linux 6.6; UI render: default; VCL: gtk3
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Calc: threaded
or
Version: 25.2.0.3 (AARCH64) / LibreOffice Community
Build ID: e1cf4a87eb02d755bce1a01209907ea5ddc8f069
CPU threads: 4; OS: Linux 6.6; UI render: default; VCL: gtk3
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Flatpak
Calc: threaded
or
Version: 7.4.7.2 / LibreOffice Community
Build ID: 40(Build:2)
CPU threads: 4; OS: Linux 6.6; UI render: Skia/Vulkan; VCL: gtk3
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Debian package version: 4:7.4.7-1+deb12u6
Calc: threaded
Doesnt matter if the call happens via APSO , via …Execute or …Organize…Python…
Have you tried using the example.ods document I uploaded?
BTW: I am using Windows 10
No I didnt, but now (with disabled Java) I can confirm!
Dont use Scriptforge in general!
What do you mean?
It means, you dont need it (especially as python-programmer) because its just roundabout 30KLOC of boilerplate!
Then could you please tell me how would you write the same python code without Scriptforge??
I am not a professional programmer BTW, but I am willing to learn more.
Strictly the same:
from msgbox import MsgBox
from com.sun.star.awt.WindowClass import TOP, SIMPLE
from com.sun.star.awt.PushButtonType import STANDARD, OK, CANCEL, HELP
def messagebox( message, deko=SIMPLE, title="Read_ME" ):
msg = MsgBox( XSCRIPTCONTEXT.ctx )
msg.addButton( OK )
msg.addButton( CANCEL )
msg.show( message, deko, title)
def main(*_):
doc = XSCRIPTCONTEXT.getDocument()
sheet = doc.Sheets['Sheet1']
last_row = int(sheet.RowDescriptions[-1].split()[1])
messagebox(f"{last_row = }")
But meanwhile development you would just print
def main(*_):
doc = XSCRIPTCONTEXT.getDocument()
sheet = doc.Sheets['Sheet1']
last_row = int(sheet.RowDescriptions[-1].split()[1])
print(f"{last_row = }")
Thank you karolus! It Works perfectly fine !!
Could I please ask you a pair of questions, as I am trying to learn?
.
Question 1: Why is it neccesary to import:
from com.sun.star.awt.WindowClass import TOP, SIMPLE
from com.sun.star.awt.PushButtonType import STANDARD, OK, CANCEL, HELP
if these seem to be already imported in msgbox module?
I know it does not work as I tried for example:
from msgbox import SIMPLE
but I don´t know why
.
Question 2: In other thread you showed me the LibreOffice API links (thank you), but I can´t find RowDescriptions method anywhere, not even in Google. Where did you get that from? Where could I learn all this by myself?
.
Thank you very much!
matter of scope.
see e.g. python - `from ... import` vs `import .` - Stack Overflow
not a method here, but a Sequence :
definitely a pain to navigate down to find the exact provider from LibreOffice: Spreadsheet Service Reference
in such case maybe easier to find your way up from Dev Tools :
then
then
LibreOffice: XChartDataArray Interface Reference
etc etc getrowdescriptions (full) in projects: core - OpenGrok search results
I agree, but mri.oxt exists as a convinient Alternative!
And with Jupyter notebook plus initial ~30 LOC you’ll have a full featured Environment wich provides also Code-completion deep into the LO-Object-Hierarchy!
import uno
from pythonscript import ScriptContext
PIPENAME = "your_pipe_name_here"
args = f"pipe,name={PIPENAME}"
local = uno.getComponentContext()
resolver = local.ServiceManager.createInstance("com.sun.star.bridge.UnoUrlResolver")
ctx = resolver.resolve( f"uno:{args};"
"urp;"
"StarOffice.ComponentContext")
createUnoService = ctx.ServiceManager.createInstance
XSCRIPTCONTEXT = ScriptContext( ctx , None, None )
ps. precondition to »allow« the connection above:
In LO navigate to ⇒ Tools ⇒ Options ⇒ LO ⇒ Extended ⇒⇒ ExpertConfig
search for: »ooSetupConnectionURL« and edit the node to pipe,name=your_pipe_name;urp;StarOffice.Servicemanager
By the way guys, I have not marked anything as a solution since your help with the code was not related to LibreOffice/Scriptforge asking to enable Java environment. It is also not confirmed to be a bug, so I haven’t marked mikekaganski’s answer as a solution either. In case I am wrong, please let me know.
.
In case you are interested, here is the reported bug
.
EDIT: It has been confirmed as a bug at the report page, so I mark @mikekaganski answer as solution. Thank you very much to all of you!