python - libreoffice 宏 - 在文本字段上切换启用可见
问题描述
我正在使用 python 宏对 libreoffice 编写器文件执行操作。而且我希望可以切换 TextField 的 EnableVisible 标志。
这意味着,在双击该字段时,切换您可以使用的小标志,使其可见或不可见。
到目前为止,我在我的代码中得到了这个:
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:未知属性:启用(调用模块(...)file.py中的函数toggle_field时出错(:EnableVisible
更新 :
tf.IsFieldDisplayed = False
或者
tf.setPropertyValue('IsFieldDisplayed', False)
不再是未知属性,但我收到此错误消息:
com.sun.star.beans.UnknownPropertyException:IntrospectionAccessStatic_Impl::setPropertyValueByIndex(),索引 13 处的属性是只读的(调用模块 (...)file.py 中的函数 toggle_field 时出错(:IntrospectionAccessStatic_Impl::setPropertyValueByIndex(),属性位于索引 13 是只读的
看起来不公平,因为它在文档中不是只读的,BASIC 可以修改它(https://wiki.documentfoundation.org/images/b/b0/BH5009-Macros.pdf第 19 页)
解决方案
经过共同的研究工作,事实证明该属性称为IsVisible
:
tf.IsVisible = not tf.IsVisible
推荐阅读
- css - 单击地图时消除基于 mapbox-gl-js 的地图周围的黑色边框
- c++ - C++ 获取 SQL_VARCHAR?
- javascript - 如何将对象视为数组并对其进行迭代并将响应保存在具有 trie 数据结构的 javascript 中?
- docker - 删除最近不使用的 docker 镜像
- prometheus - 我在 strconv.ParseFloat 中收到错误:解析“2\r”:无效语法普罗米修斯
- javascript - Firebase 实时数据库,这两个查询有什么区别?
- vue.js - VS Code 不显示模型预览
- c++ - qt5多行按钮,每行有多种样式
- javascript - 如何避免使用firestore中的子集合拒绝权限?
- sql - SQL 中的 LAG 函数