Hello, our product uses LibreOffice Macro to add custom functions that send requests to the backend to calculate results. This scheme works perfectly fine for a while, but now we need to process a huge amount of documents as fast as possible to calculate all formulas in the file.
The first problem is that starting the LibreOffice instance (headless) takes too long, ~0.8-1.5 seconds. What we have found is that we can start one headless LibreOffice in server mode.
But there is a second problem: we can not provide any information (like JWT token and internal object ID) when trying to open the document, maybe we just don’t know how.
Is it possible to provide any data to the document without editing it when we invoke the macro?
Or possibly can we optimize the startup time of the LibreOffice instance?
There is an example request to run our macro on Python:
def run_macro(file_url, token, internal_id):
ctx = uno.getComponentContext()
resolver = ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", ctx
)
ctx_remote = resolver.resolve(
"uno:socket,host=127.0.0.1,port=2002;urp;StarOffice.ComponentContext"
)
smgr = ctx_remote.ServiceManager
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx_remote)
props = [
prop("Hidden", True),
prop("ReadOnly", True),
prop("AsTemplate", False),
prop("UpdateDocMode", 0),
prop("MacroExecutionMode", 0),
prop("OpenNewView", False),
prop("SkipImages", True),
prop("FilterOptions", "calc8"),
]
# We need to load the document with token and internal_id to get access to it in the Macro
doc = desktop.loadComponentFromURL(file_url, "_blank", 0, props)
doc.calculateAll()
Also, there is a macro code structure:
class CompanyExt(unohelper.Base, XINTERFACE):
version = "1.5"
def __init__(self, ctx):
self.internal_id = ...
self.token = ...
...
def CUST_FORMULA(self, *args):
...
# request here
...
def createInstance(ctx):
return CompanyExt(ctx)
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(
createInstance, 'com.company.company.oxt',
('com.sun.star.sheet.AddIn',),)