【问题标题】:Error in calling a Python script from a Basic function从基本函数调用 Python 脚本时出错
【发布时间】:2018-06-30 01:28:44
【问题描述】:

我是 Python 和 Basic 的新手。我正在尝试从 LibreOffice (LO) Calc 中的 Google 表格复制 IMPORTHTML 函数。简而言之,我想在 Calc 中创建一个 GetHtmTable(Url, Table Index) Basic 函数,它将调用 Python 脚本来完成繁重的工作。

所以基于 Villeroy 的 great example,我在 LO 5.1.6.2 中实现。调用 Python 脚本 sheetFunctions.py 以熟悉该过程的基本 SOUNDEX 函数。我的环境是 Linux Mint 18,我使用 Python 3,我导入了各种库,例如 Uno、PIP 等。我使用PycharmProjects 作为 Python 编辑器。

我在 LO Calc 菜单 tools->macro->organize macros->python 下清楚地看到了sheetFunctions.py Python 脚本,它确实在文件夹/usr/lib/libreoffice/share/Scripts/python 中。

每当我运行 SOUNDEX Basic 函数时,我都会看到以下错误消息:

BASIC 运行时错误。发生异常类型: com.sun.star.script.provider.ScriptFrameworkErrorException 消息: : 一个 打开文件时出错
/usr/lib/libreoffice/program/pythonscript.py:429 在函数中 getModuleByUrl() [lastRead = self.sfa.getDateTimeModified( url )]
/usr/lib/libreoffice/program/pythonscript.py:993 在函数中 getScript() [mod = self.provCtx.getModuleByUrl(fileUri)]

我尝试调试SOUNDEX基本功能,发现阻塞点是程序运行时getScript("vnd.sun.star.script:sheetFunctions.py$soundex?language=Python&location=user")

我已经尝试了几天来克服这个错误,但我必须承认失败。

我想知道我是否需要在 Basic 环境中引入一些额外的扩展,或者在 Linux/Python 环境中引入缺少的插件?

我将 location=user 更改为 location=document 并再次卡住。由于命令sudo apt-get install libreoffice-script-provider-python,我最近添加了 libreoffice-script-provider-python,但这并没有帮助。我还在 Calc 文档中嵌入了 Python 脚本,但同样没有解决问题。

【问题讨论】:

  • 次要问题:问题应该是imported uno,而不是implemented uno。

标签: python libreoffice-calc libreoffice-basic


【解决方案1】:

位置名称不匹配。自写脚本的标准位置是user directory。这是location=user,例如~/.config/libreoffice/4/user/Scripts/python

然后是location=share,指的是你问题中的路径。这些参数在URI Specification 中的Python 脚本 下进行了描述。

另请参阅我对this question 的回答。如果您还没有,请务必尝试 APSO 扩展。尤其是在使用location=document 时,APSO 会有所帮助,因为嵌入需要几个步骤,包括编辑 manifest.xml。

【讨论】:

    猜你喜欢
    • 2012-01-23
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    • 1970-01-01
    • 2015-04-13
    相关资源
    最近更新 更多