[]
        
(Showing Draft Content)

GC.Spread.Sheets.Shapes.ShapeCollection

Class: ShapeCollection

Sheets.Shapes.ShapeCollection

Table of contents

Constructors

Methods

Constructors

constructor

new ShapeCollection(sheet)

Represents a shape manager that managers all shapes in a sheet.

Parameters

Name Type Description
sheet Worksheet The worksheet.

Methods

add

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

Add a new shape to shape collection

example

// This example shows how to add a new shape
var shape = activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);

Parameters

Name Type Description
name string The name of the shape. If leave blank an unique name will be generated.
autoShapeTypeOrModel IShapeModel | AutoShapeType The type of the shape (for one of the buildin types) or the model for custom shape.
left? number The x location of the shape.
top? number The y location of the shape.
width? number The width of the shape.
height? number The height of the shape.

Returns

Shape

The shape that has been added to the sheet.


addCameraShape

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

Add a new camera shape to shape collection

example

// This example shows how to add a new camera shape
var shape = activeSheet.shapes.addCameraShape("camera shape 1", 'Sheet1!A1:A8', 100, 50, 100, 150);

Parameters

Name Type Description
name string The name of the camera shape. If leave blank an unique name will be generated.
range string The range of the shape generated from, it should be a range formula, like Sheet1!A1:A8.
left? number -
top? number -
width? number -
height? number -

Returns

CameraShape

The shape that has been added to the sheet.


addConnector

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

Add a Connector Shape to shape collection

example

//This example shows how to add a connector shape
var shape1 = activeSheet.shapes.addConnector("shape1", GC.Spread.Sheets.Shapes.ConnectorType.elbow, 200, 50, 300, 200);

Parameters

Name Type Description
name string The name of the shape. If leave blank an unique name will be generated.
connectorType ConnectorType The type of the connector.
beginX? number The x location of the start point for the connector shape.
beginY? number The y location of the start point for the connector shape.
endX? number The x location of the end point for the connector shape.
endY? number The y location of the end point for the connector shape.

Returns

ConnectorShape

The connector 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

example

// 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);

Parameters

Name Type Description
name string The name of the shape. If leave blank an unique name will be generated.
src string The src of the picture.
left? number The x location of the picture shape.
top? number The y location of the picture shape.
width? number The width of the picture shape.
height? number The height of the picture shape.

Returns

PictureShape

The picture shape that has been added to the sheet.


all

all(): Shape[]

get all shapes

example

// This sample shows how to get all shapes in shape collection
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[]

all shapes


clear

clear(): void

clear all shapes

example

//This example shows how to clear all shapes in shape collection
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

Get a shape with name

example

//This example shows how to get a shape with name.
activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
activeSheet.shapes.get("shape1");

Parameters

Name Type Description
name string The name of the shape.

Returns

Shape

The Shape


group

group(shapes): GroupShape

Groups the Shapes.

example

//This sample shows how to group some shapes
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[] The shapes to group.

Returns

GroupShape

The Shape group.


remove

remove(name): void

remove a shape

example

//This example shows how to remove a shape
activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
activeSheet.shapes.remove("shape1");

Parameters

Name Type Description
name string The name of the shape.

Returns

void


snapMode

snapMode(value?): void | SnapMode

Gets or sets whether to align shape to grid line or the other shapes.

example

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

Parameters

Name Type Description
value? SnapMode Whether to snap shapes to the grid line or other shapes.

Returns

void | SnapMode

If no value is set, returns which snapMode use.


ungroup

ungroup(groupShape): void

Separate a groupShape to some shapes

example

//This sample shows how to separate a groupShape to some shapes
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 The groupShape to separate.

Returns

void


zIndex

zIndex(shapeName, zIndex): number

Get or set the z-index for a shape

example

//This is a sample shows how to use 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 The name of the shape
zIndex number The z-index for the shape. The zIndex should be between 0 to all shapes length(not contains). A shape with greater zIndex is always in front of a shape with a lower zIndex.

Returns

number