Programming OpenOffice with External Python Project

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
bobthebuilder
Posts: 1
Joined: Fri Apr 07, 2023 12:43 am

Programming OpenOffice with External Python Project

Post by bobthebuilder »

I am unable to program Openoffice documents from a python project.

Here is my Python code:
filename = 'somefile.ods'

import Danny.OOo.OOoLib as OOoLib
import unohelper
import os.path

url = unohelper.systemPathToFileUrl(
    os.path.abspath(filename))
desktop = OOoLib.getDesktop()
doc = desktop.loadComponentFromURL(
    url, "_blank", 0, () )

The error I get is:
File "c:\users\public\documents\python\openofficetest.py", line 3, in <module>
import Danny.OOo.OOoLib as OOoLib
File "c:\users\public\documents\python\Danny\OOo\OOoLib.py", line 38, in <module>
import uno
ModuleNotFoundError: No module named 'uno'

First I am not sure which folder to put the “Danny.OOo.OOoLib as OOoLib”
Second what does the “No module named 'uno” error mean?

Can anyone answer this and show what is needed to eliminate the errors and have Python talk to OpenOffice.
Last edited by MrProgrammer on Fri Apr 07, 2023 4:44 am, edited 1 time in total.
Reason: Added formatting tags for python program
windows openoffice 4.1.13
Mountaineer
Posts: 316
Joined: Sun Sep 06, 2020 8:27 am

Re: Programming OpenOffice with External Python Project

Post by Mountaineer »

From your paths I see you are on windows. You are aware you usually have two pythons on your system, after you installed python for windows? One installed by you for external projects, one inside LibreOffice - and they don't know anything of each other.

Another problem may be APSO wich can hide pythonpath from projects inside LibreOffice...

No module named 'uno' means, the active python can not find a module named uno in its search path. If this is a problem of the module not being there or an incomplete search-path or just activation if the wrong venv I can't say.
OpenOffice 3.1 on Windows Vista
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Programming OpenOffice with External Python Project

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply