Getting python to import uno / pyuno

前端 未结 1 574
北海茫月
北海茫月 2020-12-20 01:24

I\'ve been searching all day for a solution and can\'t seem to find anything that works, just a bunch of a leads that seem outdated or non-functional.

I\'m basically

相关标签:
1条回答
  • 2020-12-20 01:42

    For running uno from a different python I found that I had to set three values. On Win7 you may set all three as user defined environment values for the user account. Log off and on again for them to get working.

    After some try&error I came up with the following solution.

    In your lib\site-packages folder of your pythoninstallation add a OpenOffice.pth file with the path to your installations subfolder program like:

    content of OpenOffice.path:
    C:\Program Files (x86)\OpenOffice.org 4\basis\program
    

    I did not get it working on Win7 with Python 2.7 to set this value from within the script. Thats why I use the .pth file. With OpenOffice 3.x the path wants to be to C:\Program Files (x86)\OpenOffice.org 3\basis\program.

    import os
    os.environ["URE_BOOTSTRAP"] = r"vnd.sun.star.pathname:C:\Program Files (x86)\OpenOffice 4\program\fundamental.ini"
    os.environ["PATH"] += r";C:\Program Files (x86)\OpenOffice 4\program"
    import uno
    

    Within your script set two environ values to the fundamental.ini and to the subfolder \program.

    With OpenOffice 3.x the second environ has got to look like this

    os.environ["PATH"] += r";C:\Program Files (x86)\OpenOffice.org 3\URE\bin"
    

    Of course you will have to change those paths to fit your installation. You may want to drop the BOOTSTRAP right after you imported uno, because that causes conflicts if you are running differen versions of OpenOffice or LibreOffice on the same machine.

    os.environ.pop("URE_BOOTSTRAP")
    

    Important! This will only work if your python is the same version as the python that comes with you OpenOffice, i.e. OpenOffice 3.x python 2.6 OpenOffice 4.x python 2.7 LibreOffice 4.x python 3.3

    0 讨论(0)
提交回复
热议问题