Did you try the ScriptForge library shipped with LibreOffice:
https://help.libreoffice.org/latest/en-US/text/sbasic/shared...
See the SFDocuments.Calc service there. ScriptForge makes it more convenient to work with the API.
Using it with Python: https://help.libreoffice.org/latest/en-US/text/sbasic/shared...