sudo apt-get install python3-uno
% dpkg-query -L python3-uno | grep dist
Change this path as required
% export PYTHONPATH=/usr/lib/python3/dist-packages
% python3 -m pip install pyoo
Note: all libreoffice executables must be shut down first
This will start a headless window that will be used as a bridge for python script to access. This process must be left alive for pyoo to work
# soffice --accept="pipe,name=oo_pyuno;urp;" --norestore --nologo --nodefault # --headless
#!/usr/local/bin/python3
import pyoo
desktop = pyoo.Desktop(pipe='oo_pyuno')
wkbk = desktop.open_spreadsheet("<xls_file_name>")
sheet = wkbk.sheets['<sheet_name>']
# Write value 'foo' to cell E5 on <sheet_name>
sheet[4,4].value='foo'
wkbk.save()
wkbk.close()
See: https://pypi.org/project/pyoo/ for more details