I have the following problem. My LO is hosted on a server and I don’t have GUI access.
I need to change the parameters so that the document itself rewrites the formulas.
I tried to set up the formulas more correctly, as well as register the config manually, it did not help.
Is there a special command for this?
The question is not very specific, however; I will assume the following:
- Connect to server with LibreOffice running in Headless mode
- Load a calc document
- Access the sheet of the document
- Write or re-write formulas for give cells.
- Save the document
OOO Development Tools (OooDev) Can do all of this.
Connect to server
OooDev can connect is two different way. ConnectSocket() and ConnectPipe()
Note the headless=True
flag to connect to LibreOffice without a GUI interface.
from ooodev.utils.lo import Lo
loader = Lo.load_office(
connector=Lo.ConnectSocket(headless=True, host='somedomain.com', port=2002)
)
See Also: Python LibreOffice Programming Part 1: Basics Chapter 2. Starting and Stopping
Load Calc document and access sheet
from ooodev.office.calc import Calc
doc = Calc.open_doc(fnm="path/to/my/doc.ods", loader=loader)
sheet = Calc.get_sheet(doc=doc, index=0)
Write or re-write formula
Set cell values to the desired formula using Calc.set_val()
See:
# set up equation formulae without inequalities
Calc.set_val(value="=120*B1 + 210*B2", sheet=sheet, cell_name="B4")
Calc.set_val(value="=110*B1 + 30*B2", sheet=sheet, cell_name="B5")
Calc.set_val(value="=B1 + B2", sheet=sheet, cell_name="B6")
Save Document
Save document using Lo.save_doc()
Lo.save_doc(doc=doc, fnm="somepath/somefile.ods")