我正在尝试使用Windows10上的LibreOffice 5在形状中创建一个散列标记模式,使用LibreOffice附带的Python3.3。三分之二的代码与这个帖子相似,还有一些关于在代码清单末尾创建散列标记的问题。
这是我尝试过的Python代码。
import sys
print(sys.version)
import socket
import uno
# get the uno component context from the PyUNO runtime
localContext = uno.getComponentContext()
# create the UnoUrlResolver
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext )
# connect to the running office
ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager
# get the central desktop object
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
model = desktop.getCurrentComponent()
# Create the shape
def create_shape(document, x, y, width, height, shapeType):
shape = model.createInstance(shapeType)
aPoint = uno.createUnoStruct("com.sun.star.awt.Point")
aPoint.X, aPoint.Y = x, y
aSize = uno.createUnoStruct("com.sun.star.awt.Size")
aSize.Width, aSize.Height = width, height
shape.setPosition(aPoint)
shape.setSize(aSize)
return shape
def formatShape(shape):
shape.setPropertyValue("FillColor", int("FFFFFF", 16)) # blue
shape.setPropertyValue("LineColor", int("000000", 16)) # black
aHatch = uno.createUnoStruct("com.sun.star.drawing.Hatch")
#HatchStyle = uno.createUnoStruct("com.sun.star.drawing.HatchStyle")
#aHatch.Style=HatchStyle.DOUBLE;
aHatch.Color=0x00ff00
aHatch.Distance=100
aHatch.Angle=450
shape.setPropertyValue("FillHatch", aHatch)
shape.setPropertyValue("FillStyle", "FillStyle.DOUBLE")
shape = create_shape(model, 0, 0, 10000, 10000, "com.sun.star.drawing.RectangleShape")
formatShape(shape)
drawPage.add(shape)此代码应在矩形内设置双交叉模式,但不显示矩形内的ups。
aHatch = uno.createUnoStruct("com.sun.star.drawing.Hatch")
#HatchStyle = uno.createUnoStruct("com.sun.star.drawing.HatchStyle")
#aHatch.Style=HatchStyle.DOUBLE;
aHatch.Color=0x00ff00
aHatch.Distance=100
aHatch.Angle=450
shape.setPropertyValue("FillHatch", aHatch)
shape.setPropertyValue("FillStyle", "FillStyle.DOUBLE")设置孵化样式模式的行:
uno.RuntimeException: pyuno.getClass: 失败,并出现以下错误
com.sun.star.drawing.HatchStyleis a ENUM, expected EXCEPTION,发布于 2016-05-06 02:37:00
uno.createUnoStruct("com.sun.star.drawing.HatchStyle") = HatchStyle
这是失败的,因为HatchStyle是一个枚举,而不是一个结构。要使用HatchStyle枚举,请遵循enum链接中python示例中的三种方式之一。
shape.setPropertyValue("FillStyle","FillStyle.DOUBLE")
从示例中看,您似乎混淆了"FillStyle.HATCH“和"HatchStyle.DOUBLE”。这就是Python中应该包含的代码:
from com.sun.star.drawing.FillStyle import HATCH
shape.setPropertyValue("FillStyle", HATCH)这似乎也缺失了:
drawPage = model.getDrawPages().getByIndex(0)https://stackoverflow.com/questions/37060560
复制相似问题