Libreoffice宏如何使用外部python(不是embedde)脚本通过shell函数

时间:2015-12-17 05:42:01

标签: python-2.7 libreoffice

Libreoffice宏shell函数在shell,PHP或者不是python时工作正常, 但是shell("x.py")被迫只使用嵌入式python。我想使用外部python,也许存在一些解决方法。

2 个答案:

答案 0 :(得分:2)

我假设你问的是从LibreOffice Basic宏调用,因为Shell是一个Basic函数。例如,您的代码可能如下所示:

Sub CallPython
    filepath = "C:\Python33\python.exe C:\OurDocs\x.py"
    Shell(filepath,2)
End Sub

我想知道"嵌入式python"您的系统正在使用的版本。要找到答案,请将此代码放在x.py:

import sys
# change this path to a directory located on your system
with open("c:/users/jimstandard/desktop/x.txt", 'w') as f:
    f.write(sys.version)

要使用不同版本的Python,请在上面的filepath变量中使用不同的路径。

我经常在LibreOffice中使用Python,但我没有这样做。相反,我使用PyUNO编写宏,这通常根本不涉及Basic。也许这就是你真正想做的事情。所有的宏代码都放在Python文件中,并用Python编写而不是Basic。

有关如何使用PyUNO的信息,请参阅https://wiki.openoffice.org/wiki/Python

答案 1 :(得分:-1)

以下是解决方法:

  1. 使用文本

    创建bat文件
    C:\external_python\python.exe my_py.py
    
  2. 从基本

    运行
    oSvc = createUnoService("com.sun.star.system.SystemShellExecute")
    oSvc.execute(ConvertToUrl("C:\Windows\explorer.exe "),"D:\my_bat.bat", 0)