【问题标题】:How to check paragraph adjustment using pyUNO library in Libre/Open Office?如何在 Libre/Open Office 中使用 pyUNO 库检查段落调整?
【发布时间】:2015-03-13 13:55:48
【问题描述】:

com.sun.star.style.ParagraphProperties 服务支持该属性 ParaAdjust,支持来自 com.sun.star.style.ParagraphAdjust 的 5 个值 (ParagraphPropertiesParagraphAdjust)。

要设置值,可以使用以下两种方法之一:

cursor.ParaAdjust = com.sun.star.style.ParagraphAdjust.RIGHT
cursor.setPropertyValue('ParaAdjust', com.sun.star.style.ParagraphAdjust.RIGHT)

要检查第一次尝试的值是:

if cursor.ParaAdjust == com.sun.star.style.ParagraphAdjust.RIGHT:
    ...

但没用。

检查:

type(cursor.ParaAdjust)
----> <class 'int'>
type(com.sun.star.style.ParagraphAdjust.RIGHT)
----> <class 'uno.Enum'>

是的,我假设这些是常量(请参阅下面的注释),这是我的错。

现在,uno.Enum 类有两个属性typeNamevalue,所以我试过了:

if cursor.ParaAdjust == com.sun.star.style.ParagraphAdjust.RIGHT.value:
    ...

但也没有用!

检查:

type(com.sun.star.style.ParagraphAdjust.RIGHT.value)
----> <class 'string'>
print(com.sun.star.style.ParagraphAdjust.RIGHT.value)
----> 'RIGHT'

设置ParaAdjust属性,然后打印它的实际值,我得到:

LEFT    = 0
RIGHT   = 1
BLOCK   = 2
CENTER  = 3
STRETCH = 0
(note that STRETCH is considered as LEFT,
 a bug or something not implemented?)

所以:

  • 这些值在哪里定义?
  • 如何使用 UNO API 获取这些值?
  • 我是否遗漏了官方文档中的某些内容?

注意

在 LibreOffice 4.0(也可能在旧版本中)中,您可以通过以下方式获取此值:

uno.getConstantByName('com.sun.star.style.ParagraphAdjust.RIGHT')

从 4.1 版开始,它不再工作了(正确的,不是一个常数)。

【问题讨论】:

    标签: openoffice.org libreoffice uno pyuno


    【解决方案1】:

    感谢来自 OpenOffice 论坛 (link) 的“hanya”,这里有一些用于映射 ParagraphAdjust 值的 python 代码:

    def get_paragraph_adjust_values():
        ctx = uno.getComponentContext()
        tdm = ctx.getByName(
                "/singletons/com.sun.star.reflection.theTypeDescriptionManager")
        v = tdm.getByHierarchicalName("com.sun.star.style.ParagraphAdjust")
        return {name : value
                for name, value
                in zip(v.getEnumNames(), v.getEnumValues())}
    

    在 python 2.6 中,不支持字典的理解语法,可以使用 dict() 函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-19
      • 2013-03-05
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多