Using SCFunctionAccess::callFunction from Python

Sebastian Henschel sebastian.henschel at passiv.de
Thu Mar 6 09:45:49 UTC 2025


Hi there!

As this does not concern the development of LibreOffice directly, it is 
about software development or rather using an LO API.
Please send me elsewhere if this is not the appropriate place.
I was doing some reasearch the last couple of days and also toying with 
code and have not found a satisfying answer yet.

The short version of my question is:
How can i run `SCFunctionAccess::callFunction` from Python wihout UNO?

The long version:
I have this large legacy application written in Excel which was made 
compatible with LibreOffice in recent years.
This application is still updated on a regular basis.
Now, there is the need to make this application (or parts of it) 
available as a web service.
As i already have a server running Django providing various web 
services, i would like to use Python to connect to that application.
Translating the functionality of the original app to Python on every 
update would be quite a pain. I already have that in production for one 
feature of the application.

Using the UNO bridge via Python seems to work, but loading the Excel 
file takes about 25s which is unacceptable to be run on each web request.
I also tried OpenPyXL which loads the document a few seconds faster, but 
still needs an unacceptable 20s. Also, the process uses a huge amount of 
memory: 600 MB compared to 25 MB with UNO (measured by /usr/bin/time 
-v). And afaik, i can not change cell contents and then have functions 
like COUNTIF run on the changed contents.

So the current idea is to transpile the Excel file to a Python package 
which can be repeated every time there is an update to the application.
Basically, I have the transpilation part sussed out, the problem is now 
the implementation of all the LibreOffice/Excel functions, like COUNTIF 
or exact semantics of e.g. '+' in a LibreOffice context.
The hope is that SCFunctionAccess::callFunction (from 
core/sc/source/ui/unoobj/funcuno.cxx) can do that for me.
To be able to use that from Python, i could wrap it using boost::python 
or swig. Does anyone have experience with wrapping LibreOffice functions?
Or maybe ctypes? Which .so file in `/usr/lib/libreoffice/program/` 
(Debian-based OS) contains that method/class (have not studied the 
LibreOffice build process intensively yet)? I do not know if ctypes 
works with C++ libraries, though.
There also used to be LOK, but its somewhat gone/entwined with GTK. 
Could that help?
In any case, for all these wrappers, I fear, I still would need to load 
the whole document into an instance of `SCFunctionAccess` which might 
take too much time. Any opionions on that?

Thanks for reading this so far and i hope i have made myself clear enough.
Do you reckon wrapping the C++ code for Python is viable?
Or perhaps, there is a totally different approach you can think of?

Thanks in advance,
  Sebastian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20250306/ec07bdc1/attachment.sig>


More information about the LibreOffice mailing list