首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用LibreOffice绘制形状的散列标记时出现LibreOffice问题

使用LibreOffice绘制形状的散列标记时出现LibreOffice问题
EN

Stack Overflow用户
提问于 2016-05-05 21:27:44
回答 1查看 164关注 0票数 0

我正在尝试使用Windows10上的LibreOffice 5在形状中创建一个散列标记模式,使用LibreOffice附带的Python3.3。三分之二的代码与这个帖子相似,还有一些关于在代码清单末尾创建散列标记的问题。

这是我尝试过的Python代码。

代码语言:javascript
复制
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。

代码语言:javascript
复制
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")

设置孵化样式模式的行:

代码语言:javascript
复制
uno.RuntimeException: pyuno.getClass: 

失败,并出现以下错误

代码语言:javascript
复制
com.sun.star.drawing.HatchStyleis a ENUM, expected EXCEPTION,

下面是我参考的一些Java基性示例的链接。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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中应该包含的代码:

代码语言:javascript
复制
from com.sun.star.drawing.FillStyle import HATCH
shape.setPropertyValue("FillStyle", HATCH)

这似乎也缺失了:

代码语言:javascript
复制
drawPage = model.getDrawPages().getByIndex(0)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37060560

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档