跳到主要内容

MergeShapes

将绘图对象数组合并为新形状。生成的形状采用数组中第一个绘图对象的格式。

备注

在电子表格编辑器中,文档生成器不支持此方法,它仅在编辑器中有效。

语法​

expression.MergeShapes(drawings, operation);

expression - 表示 Api 类的变量。

参数​

名称必需/可选数据类型默认值描述
drawings必需Drawing[]包含至少两个来自同一页面、幻灯片或工作表的绘图对象的数组。其中至少一个必须是形状。
operation必需ShapesMergeOperation合并操作。

返回值​

Drawing[] | null

示例​

将文档中两个重叠的形状合并为一个形状。

// Build a custom shape from simple shapes with the union operation.

// Unite a rectangle and an ellipse into one shape filled with the color of the rectangle.

let doc = Api.GetDocument();
let fill1 = Api.CreateSolidFill(Api.Color(255, 111, 61));
let fill2 = Api.CreateSolidFill(Api.Color(51, 51, 51));
let stroke = Api.CreateStroke(0, Api.CreateNoFill());
let rectangle = Api.CreateShape("rect", 60 * 36000, 40 * 36000, fill1, stroke);
let ellipse = Api.CreateShape("ellipse", 40 * 36000, 40 * 36000, fill2, stroke);
doc.AddDrawingToPage(rectangle, 0, 30 * 36000, 40 * 36000);
doc.AddDrawingToPage(ellipse, 0, 70 * 36000, 40 * 36000);
Api.MergeShapes([rectangle, ellipse], "union");