add_freeform方法

add_freeform(self, upper_left_row, top, upper_left_column, left, height, width, paths)

向工作表添加自由形状。

返回

自由形状。


def add_freeform(self, upper_left_row, top, upper_left_column, left, height, width, paths):
    ...
范围类型描述
upper_left_rowint左上行索引。
topint表示自由形状与其左行垂直方向的偏移量,以像素为单位。
upper_left_columnint左上角的列索引。
leftint表示自由形状与其左列的水平偏移量,以像素为单位。
heightint表示自由形状的高度,以像素为单位。
widthint表示自由形状的宽度,以像素为单位。
pathslist表示用户定义的路径

注意事项

注意:参数中的宽和高可以是任意正整数值,而不是paths指定的ShapePath数组的总宽和高。它们之间的关系是缩放-填充关系,即每个ShapePath对象都会根据宽和高进行缩放。因此,当paths中有多个对象时,需要合理设计每个ShapePath对象以满足预期。当只有一个ShapePath对象且没有其他需求时,将对象的宽和高作为参数值传递是一个不错的解决方案。

例子

from aspose.cells.drawing import ShapePath

# Custom figure
shapePath = ShapePath()
shapePath.move_to(60, 45)
shapePath.arc_to(25, 25, 0, 270)
shapePath.close()
shapePath.move_to(60, 20)
shapePath.line_to(110, 70)
shapePath.line_to(125, 155.5)
shapePath.arc_to(35.5, 35.5, 0, 270)
shapePath.close()
shapePath.move_to(150, 45)
shapePath.arc_to(25, 25, 0, 270)
shapePathW = shapePath.width_pixel
shapePathH = shapePath.height_pixel
shapePath1 = ShapePath()
shapePath1.move_to(0, 0)
shapePath1.cubic_bezier_to(48.24997, 0.6844,                                 96.5, -7.148871,                                 130, 11.517795)
shapePath1.cubic_bezier_to(163.5, 30.18446,                                 182.24997, 75.351,                                 201, 120.517795)
shapePath1.move_to(150, 80)
shapePath1.arc_to(25, 25, 0, 270)
if shapePath1.width_pixel > shapePathW:
    shapePathW = shapePath1.width_pixel
if shapePath1.height_pixel > shapePathH:
    shapePathH = shapePath1.height_pixel
# Notice: shapePathH and shapePathH can be any positive integer values, here we just simply set them.
# Insert custom figure into worksheet
shapes.add_freeform(1, 0, 1, 0, shapePathH, shapePathW, [shapePath, shapePath1])

也可以看看