You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

LibreOffice Calc嵌入式Python宏执行异常求助(按钮显隐控制及测试宏均报错)

LibreOffice Calc嵌入式Python宏执行异常求助(按钮显隐控制及测试宏均报错)

我一直尝试在工作表中运行一个嵌入式Python宏,用来根据单元格值隐藏/显示按钮。我不是编程老手,所以如果有表述错误还请见谅。

我从相关讨论里拿到了代码片段,把宏绑定到工作表的内容更改事件上,修改后的代码如下(PushButton1是从属性面板里查到的按钮名称):

def button_state_on_cell_Value(event):
    “””
    “””
    if event.AbsoluteName.endswith('$O$1'):
        sheet = event.Spreadsheet
        # next button
        PushButton1 = sheet.DrawPage[1].Control
        PushButton1.EnableVisible = event.Value==3.0 

另外,我参考了如何在LibreOffice Calc中嵌入Python脚本的方法,写了一个测试宏绑定到按钮的执行动作事件,代码没做修改:

def test(args=None):
    raise Exception("Hello from Python!")

测试第一个宏时,弹出了如下错误:

com.sun.star.uno.RuntimeException: Error during invoking function button_state_on_cell_Value in module vnd.sun.star.tdoc:/54/Scripts/python/PythonMacros.py (<class 'AttributeError'>: Control
File "C:\Program Files\LibreOffice\program\pythonscript.py", line 913, in invoke
ret = self.func( *args )
File "vnd.sun.star.tdoc:/54/Scripts/python/PythonMacros.py", line 7, in button_state_on_cell_Value)

测试第二个宏时,错误信息是:

com.sun.star.uno.RuntimeException: Error during invoking function test in module vnd.sun.star.tdoc:/54/Scripts/python/PythonMacros.py (<class 'Exception'>: Hello from Python!
File "C:\Program Files\LibreOffice\program\pythonscript.py", line 913, in invoke
ret = self.func( *args )
File "vnd.sun.star.tdoc:/54/Scripts/python/PythonMacros.py", line 13, in test
)

有没有大佬知道怎么修正这些错误?如果能用LO Basic实现按钮的隐藏/显示功能也可以!

非常感谢各位的帮助!

另外我不太敢自己乱改了,怕搞坏东西。


备注:内容来源于stack exchange,提问作者Don

火山引擎 最新活动