这是一个有效的 Python 示例:
import uno
def create_shape(document, x, y, width, height, shapeType):
shape = document.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 insert_shape():
document = XSCRIPTCONTEXT.getDocument()
drawPage = document.getDrawPages().getByIndex(0)
shape = create_shape(
document, 0, 0, 10000, 5000, "com.sun.star.drawing.RectangleShape")
drawPage.add(shape)
shape.setString("My new RectangleShape");
shape.setPropertyValue("CornerRadius", 1000)
shape.setPropertyValue("Shadow", True)
shape.setPropertyValue("ShadowXDistance", 250)
shape.setPropertyValue("ShadowYDistance", 250)
shape.setPropertyValue("FillColor", int("C0C0C0", 16)) # blue
shape.setPropertyValue("LineColor", int("000000", 16)) # black
shape.setPropertyValue("Name", "Rounded Gray Rectangle")
# Functions that can be called from Tools -> Macros -> Run Macro.
g_exportedScripts = insert_shape,
有相当完整的参考文档https://wiki.openoffice.org/wiki/Documentation/DevGuide/Drawings/Working_with_Drawing_Documents https://wiki.openoffice.org/wiki/Documentation/DevGuide/Drawings/Working_with_Drawing_Documents。特别查看“形状”页面(注意页面右侧的导航)。一方面,有一个页面根据您的要求提供了形状类型列表。
由于 Python-UNO 文档有些有限,因此您需要习惯阅读 Java 或 Basic 中的示例并将代码改编为 Python,正如我上面所做的那样。