libreoffice宏-在文本字段上切换enablevisible [英] libreoffice macro - toggle enablevisible on a textfield
问题描述
我正在使用python宏对libreoffice writer文件进行处理.而且我希望可以切换TextField的EnableVisible标志.
I'm using python macro to do things to a libreoffice writer file. And I'd like a possibility to toggle the EnableVisible flag of a TextField.
这意味着,双击该字段时,切换可使用的小标记,以使其可见或不可见.
That means, toggle the little flag that you can use, when double clicking on that field, to make it visible or invisible.
到目前为止,我的代码中已经包含了这个内容:
So far I got this in my code :
import uno
def toggle_field(field_title):
document = XSCRIPTCONTEXT.getDocument()
textfields = document.getTextFields()
enum = textfields.createEnumeration()
while enum.hasMoreElements():
tf = enum.nextElement()
if tf.VariableName == field_title:
visibility = tf.getPropertyValue('EnableVisible') #wrong
tf.EnableVisible = not visibility #wrong
tf.update() #maybe right
这给了我
com.sun.star.beans.UnknownPropertyException:未知属性:已启用(调用模块(...)file.py中的功能toggle_field时出错(:未知属性:EnableVisible
com.sun.star.beans.UnknownPropertyException: Unknown property: Enabled (Error during invoking function toggle_field in module (...)file.py (: Unknown property: EnableVisible
另外,如果我在第一条错误的行中发表评论,第二条错误的行会给我
Also, if i comment te first wrong line, the second wrong line give me
com.sun.star.beans.UnknownPropertyException:未知属性:已启用(调用模块(...)file.py(:EnableVisible
com.sun.star.beans.UnknownPropertyException: Unknown property: Enabled (Error during invoking function toggle_field in module (...)file.py (: EnableVisible
更新:
tf.IsFieldDisplayed = False
或
tf.setPropertyValue('IsFieldDisplayed', False)
不再是未知属性,但是我收到了此错误消息:
is no longer an unknown property, but i got this error message :
com.sun.star.beans.UnknownPropertyException:IntrospectionAccessStatic_Impl :: setPropertyValueByIndex(),索引13的属性为只读(调用模块(...)中的函数toggle_field时出错(.file.py(:IntrospectionAccessStatic_Impl :: setPropertyValueByIndex(),索引13处的属性为只读
com.sun.star.beans.UnknownPropertyException: IntrospectionAccessStatic_Impl::setPropertyValueByIndex(), property at index 13 is readonly (Error during invoking function toggle_field in module (...)file.py (: IntrospectionAccessStatic_Impl::setPropertyValueByIndex(), property at index 13 is readonly
似乎不公平,因为它在文档中不是只读的,并且BASIC可以对其进行修改( https://wiki.documentfoundation.org/images/b/b0/BH5009-Macros.pdf 第19页)
what seems unfair, because it is not readonly in the doc, and BASIC can modify it (https://wiki.documentfoundation.org/images/b/b0/BH5009-Macros.pdf page 19)
推荐答案
经过共同研究,事实证明该属性称为 IsVisible
:
After a common research effort, it turns out that the property is called IsVisible
:
tf.IsVisible = not tf.IsVisible
这篇关于libreoffice宏-在文本字段上切换enablevisible的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!