com.sun.star.style.ParagraphProperties服务支持属性ParaAdjust,它支持来自com.sun.star.style.ParagraphAdjust (ParagraphProperties,ParagraphAdjust)的5个值。
要设置值,可以使用以下两种方法之一:
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类有两个属性typeName和value,所以我尝试了:
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?)所以:
Note
在LibreOffice 4.0中(可能在旧版本中也是如此),您可以使用以下方法获得这个值:
uno.getConstantByName('com.sun.star.style.ParagraphAdjust.RIGHT')不再起作用的4.1版(正确地说,不是常量)。
发布于 2015-03-15 10:54:39
感谢来自论坛(链接)的“OpenOffice 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())}在python2.6中,不支持字典的理解语法,可以使用dict()函数。
https://stackoverflow.com/questions/29034087
复制相似问题