[]
        
(Showing Draft Content)

GC.Spread.Sheets.Shapes.ShapeCollection

类: ShapeCollection

Sheets.Shapes.ShapeCollection

Table of contents

构造方法

方法

构造方法

constructor

new ShapeCollection(sheet)

形状管理器,用于管理表单中的所有形状

参数

属性名 类型 说明
sheet Worksheet 表单

方法

add

add(name, autoShapeTypeOrModel, left?, top?, width?, height?): Shape

向形状集合添加新形状

代码示例

// 本示例说明如何添加新形状
var shape = activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);

参数

属性名 类型 说明
name string 形状的名称 如果保留空白,将生成一个唯一的名称
autoShapeTypeOrModel IShapeModel | AutoShapeType 形状的类型(对于一种建筑物类型)或自定义形状的模型
left? number 形状的x位置
top? number 形状的y位置
width? number 形状的宽度
height? number 形状的高度

返回值

Shape

已添加到表的形状


addCameraShape

addCameraShape(name, range, left?, top?, width?, height?): CameraShape

将新快照形状添加到形状集合

代码示例

// 本示例演示如何添加新的快照形状
var shape = activeSheet.shapes.addCameraShape("camera shape 1", 'Sheet1!A1:A8', 100, 50, 100, 150);

参数

属性名 类型 说明
name string 摄影机形状的名称.如果为空,将生成唯一名称
range string 生成形状的区域,是一个区域公式,如Sheet1!A1:A8
left? number -
top? number -
width? number -
height? number -

返回值

CameraShape

已添加到表的形状


addConnector

addConnector(name, connectorType, beginX?, beginY?, endX?, endY?): ConnectorShape

将连接器形状添加到形状集合

代码示例

//本示例说明如何添加连接器形状
var shape1 = activeSheet.shapes.addConnector("shape1", GC.Spread.Sheets.Shapes.ConnectorType.elbow, 200, 50, 300, 200);

参数

属性名 类型 说明
name string 形状的名称 如果保留空白,将生成一个唯一的名称
connectorType ConnectorType 连接器的类型
beginX? number 连接器形状起点的x位置
beginY? number 连接器形状起点的y位置
endX? number 连接器形状终点的x位置
endY? number 连接器形状终点的y位置

返回值

ConnectorShape

已添加到表的连接器形状


addFormControl

addFormControl(name, formControlType, left?, top?, width?, height?): FormControlShape

Add a new form control shape to shape collection

代码示例

// This example shows how to add a new form control shape
var shape = activeSheet.shapes.addFormControl("spinButton", GC.Spread.Sheets.Shapes.FormControlType.spinButton, 100, 50, 100, 50);

参数

属性名 类型 说明
name string 形状的名称 如果保留空白,将生成一个唯一的名称
formControlType FormControlType The type of the form control shape
left? number The x location of the form control shape.
top? number The y location of the form control shape.
width? number The width of the form control shape.
height? number The height of the form control shape.

返回值

FormControlShape

The from control shape that has been added to the sheet.


addPictureShape

addPictureShape(name, src, left?, top?, width?, height?): PictureShape

Add a new picture shape to shape collection

代码示例

// This example shows how to add a new picture shape
var shape = activeSheet.shapes.addPictureShape("Picture 1", "data:image/svg+xml;base64.....", 100, 50, 100, 100);

参数

属性名 类型 说明
name string 形状的名称。 如果名称为空字符串,则会生成唯一的名称
src string 图片的src
left? number -
top? number -
width? number -
height? number -

返回值

PictureShape

The picture shape that has been added to the sheet.


all

all(): Shape[]

获取所有形状

代码示例

// 本示例显示如何在形状集合中获取所有形状
activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
activeSheet.shapes.addConnector("shape2", GC.Spread.Sheets.Shapes.ConnectorType.elbow, 200, 50, 300, 200);
var shapes = activeSheet.shapes.all();

返回值

Shape[]

所有形状


clear

clear(): void

清除所有形状

代码示例

//本示例说明如何清除形状集合中的所有形状
activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
activeSheet.shapes.addConnector("shape2", GC.Spread.Sheets.Shapes.ConnectorType.elbow, 200, 50, 300, 200);
activeSheet.shapes.clear();

返回值

void


get

get(name): Shape

通过名称设置形状

代码示例

//本示例说明如何获取具有名称的形状
activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
activeSheet.shapes.get("shape1");

参数

属性名 类型 说明
name string 形状的名称

返回值

Shape

形状


group

group(shapes): GroupShape

对形状进行分组

代码示例

//本示例显示如何对一些形状进行分组
var shape1 = activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
var shape2 = activeSheet.shapes.addConnector("shape2", GC.Spread.Sheets.Shapes.ConnectorType.elbow, 200, 50, 300, 200);
var shapes = [shape1, shape2];
var groupShape = activeSheet.shapes.group(shapes)

参数

属性名 类型 说明
shapes Shape[] 要分组的形状

返回值

GroupShape

形状组


remove

remove(name): void

去除形状

代码示例

//本示例显示如何删除形状
activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
activeSheet.shapes.remove("shape1");

参数

属性名 类型 说明
name string 形状的名称

返回值

void


snapMode

snapMode(value?): void | SnapMode

获取或设置是否将形状与网格线或其他形状对齐

代码示例

sheet1.shapes.SnapMode(GC.Spread.Sheets.Shapes.SnapMode.grid);
var snapMode = sheet1.shapes.snapMode();

参数

属性名 类型 说明
value? SnapMode 是将吸附形状贴合到轴网线还是其他形状

返回值

void | SnapMode

如果未设置值,则返回snapMode


ungroup

ungroup(groupShape): void

将形状组分离为某些形状

代码示例

//本示例显示如何将groupShape分离为某些形状
var shape1 = activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
var shape2 = activeSheet.shapes.addConnector("shape2", GC.Spread.Sheets.Shapes.ConnectorType.elbow, 200, 50, 300, 200);
var shapes = [shape1, shape2];
var groupShape = activeSheet.shapes.group(shapes);
activeSheet.shapes.ungroup(groupShape);

参数

属性名 类型 说明
groupShape GroupShape 要分离的形状组

返回值

void


zIndex

zIndex(shapeName, zIndex): number

获取或设置形状的Z-index

代码示例

//本示例显示了如何使用Z-index
var shape1 = activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
var style = shape1.style();
style.fill.color = "red";
shape1.style(style);
var shape2 = activeSheet.shapes.addConnector("shape2", GC.Spread.Sheets.Shapes.ConnectorType.elbow, 100, 50, 200, 200);
activeSheet.shapes.zIndex("shape2"); // 1
activeSheet.shapes.zIndex("shape2", 0);

参数

属性名 类型 说明
shapeName string 形状名称
zIndex number 形状的Z-indexz-Index应该在0到所有形状长度(不包含)之间 z-Index较大的形状始终在z-Index较低的形状之前

返回值

number