Libreoffice
宏shell函数在shell,PHP或者不是python时工作正常,
但是shell("x.py")
被迫只使用嵌入式python。我想使用外部python,也许存在一些解决方法。
答案 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)
以下是解决方法:
使用文本
创建bat文件C:\external_python\python.exe my_py.py
从基本
运行oSvc = createUnoService("com.sun.star.system.SystemShellExecute")
oSvc.execute(ConvertToUrl("C:\Windows\explorer.exe "),"D:\my_bat.bat", 0)