import uno
import os
import random
file_name = "/app/fund.xls"
lock_file = "/app/.~lock.fund.xls#"
# needed because we get the /app directory from the local machine
os.remove(lock_file)
# API examples: https://wiki.openoffice.org/wiki/Python-Calc
local = uno.getComponentContext()
resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local)
context = resolver.resolve("uno:socket,host=0.0.0.0,port=8100;urp;StarOffice.ServiceManager")
remoteContext = context.getPropertyValue("DefaultContext")
desktop = context.createInstanceWithContext("com.sun.star.frame.Desktop", remoteContext)
document = desktop.loadComponentFromURL(uno.systemPathToFileUrl(file_name), "_blank", 0, ())
sheet = document.getSheets().getByIndex(1)
def run(inputs, outputs):
res = []
for _ in range(100):
for cell, inp in inputs.items():
value = random.gauss(inp[0], inp[1])
sheet.getCellRangeByName(cell).setValue(value)
document.calculate()
out = []
for cell in outputs:
out.append(sheet.getCellRangeByName(cell).getValue())
res.append(out)
return res
run({"A1": [100, 10]}, ["B1"])
Users browsing this forum: No registered users and 3 guests