[]
        
首页
开发者学堂
文档
论坛
市场
生态机会
活动
在线咨询 立即试用
(Showing Draft Content)

GC.Spread.Sheets.Shapes.ShapeCollection

Class: ShapeCollection

Sheets.Shapes.ShapeCollection

Table of contents

Constructors

Methods

Constructors

constructor

• new ShapeCollection(sheet)

表示一个管理工作表中所有形状的形状管理器。

Parameters

Name Type Description
sheet Worksheet 工作表。

Methods

add

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

向形状集合中添加新形状

example

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

Parameters

Name Type Description
name string 形状的名称。如果名称为空字符串,将生成一个唯一名称。
autoShapeTypeOrModel IShapeModel | AutoShapeType 形状的类型(用于内置类型之一)或自定义形状的模型。
left? number 形状的x位置。
top? number 形状的y位置。
width? number 形状的宽度。
height? number 形状的高度。

Returns

Shape

已添加到工作表中的形状。


addCameraShape

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

向形状集合中添加新的相机形状

example

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

Parameters

Name Type Description
name string 相机形状的名称。如果名称为空字符串,将生成一个唯一名称。
range string 生成形状的范围,应该是一个范围公式,如Sheet1!A1:A8。
left? number 相机形状的x位置,如果留空则默认值为0。
top? number 相机形状的y位置,如果留空则默认值为0。
width? number 相机形状的宽度,如果留空则默认值应与原始范围宽度相同。
height? number 相机形状的高度,如果留空则默认值应与原始范围高度相同。

Returns

CameraShape

已添加到工作表中的形状。


addConnector

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

向形状集合中添加连接器形状

example

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

Parameters

Name Type Description
name string 形状的名称。如果名称为空字符串,将生成一个唯一名称。
connectorType ConnectorType 连接器的类型。
beginX? number 连接器形状起点的x位置。
beginY? number 连接器形状起点的y位置。
endX? number 连接器形状终点的x位置。
endY? number 连接器形状终点的y位置。

Returns

ConnectorShape

已添加到工作表中的连接器形状。


addFormControl

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

向形状集合中添加新的表单控件形状

example

// 此示例展示如何添加新的表单控件形状
var shape = activeSheet.shapes.addFormControl("spinButton", GC.Spread.Sheets.Shapes.FormControlType.spinButton, 100, 50, 100, 50);

Parameters

Name Type Description
name string 形状的名称。如果名称为空字符串,将生成一个唯一名称。
formControlType FormControlType 表单控件形状的类型
left? number 表单控件形状的x位置。
top? number 表单控件形状的y位置。
width? number 表单控件形状的宽度。
height? number 表单控件形状的高度。

Returns

FormControlShape

已添加到工作表中的表单控件形状。


addPictureShape

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

向形状集合中添加新的图片形状

example

// 此示例展示如何添加新的图片形状
var shape = activeSheet.shapes.addPictureShape("Picture 1", "data:image/svg+xml;base64.....", 100, 50, 100, 100);

Parameters

Name Type Description
name string 形状的名称。如果名称为空字符串,将生成一个唯一名称。
src string 图片的源地址。
left? number 图片形状的x位置。
top? number 图片形状的y位置。
width? number 图片形状的宽度。
height? number 图片形状的高度。

Returns

PictureShape

已添加到工作表中的图片形状。


all

▸ all(): Shape[]

获取所有形状

example

// 此示例展示如何获取形状集合中的所有形状
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();

Returns

Shape[]

所有形状


clear

▸ clear(): void

清除所有形状

example

// 此示例展示如何清除形状集合中的所有形状
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();

Returns

void


get

▸ get(name): Shape

通过名称获取形状

example

// 此示例展示如何通过名称获取形状
activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
activeSheet.shapes.get("shape1");

Parameters

Name Type Description
name string 形状的名称。

Returns

Shape

形状对象


group

▸ group(shapes): GroupShape

将形状组合成组

example

// 此示例展示如何将形状组合成组
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)

Parameters

Name Type Description
shapes Shape[] 要组合的形状数组。

Returns

GroupShape

形状组


remove

▸ remove(name): void

移除形状

example

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

Parameters

Name Type Description
name string 形状的名称。

Returns

void


snapMode

▸ snapMode(value?): void | SnapMode

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

example

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

Parameters

Name Type Description
value? SnapMode 是否将形状对齐到网格线或其他形状。

Returns

void | SnapMode

如果未设置值,返回当前使用的对齐模式。


ungroup

▸ ungroup(groupShape): void

将形状组拆分为多个形状

example

// 此示例展示如何将形状组拆分为多个形状
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);

Parameters

Name Type Description
groupShape GroupShape 要拆分的形状组。

Returns

void


zIndex

▸ zIndex(shapeName, zIndex): number

获取或设置形状的z-index值

example

// 此示例展示如何使用zIndex
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);

Parameters

Name Type Description
shapeName string 形状的名称
zIndex number 形状的z-index值。zIndex应该在0到所有形状数量之间(不包含)。zIndex值较大的形状始终显示在zIndex值较小的形状前面。

Returns

number