[]
↳ GroupShape
• new GroupShape(worksheet, name?)
组合形状(GroupShape)是一种特殊的形状容器,用于将多个独立的形状对象组合为一个单一的形状组,支持对组内所有形状执行统一操作,例如移动、调整大小、删除和复制等。
| Name | Type | Description |
|---|---|---|
worksheet |
Worksheet |
组合形状所在的宿主工作表。 |
name? |
string |
可选参数。组合形状的名称。 |
▸ add(shape): void
向组合形状中添加一个形状。
example
var shape1 = activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
var shape2 = activeSheet.shapes.add("shape2", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 260, 50, 100, 150);
var groupShape = activeSheet.shapes.group([shape1, shape2]);
var shape3 = activeSheet.shapes.add("shape3", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 260, 100, 150);
// 向groupShape中添加shape3。
groupShape.add(shape3);
| Name | Type | Description |
|---|---|---|
shape |
Shape |
要添加到组合形状中的形状。 |
void
▸ all(): Shape[]
获取组合形状中的所有形状。
example
// 此示例展示如何获取组合形状中的所有形状。
var shape1 = sheet.shapes.add("myShape1", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 62 * 9, 0, 200, 200);
var shape2 = sheet.shapes.add("myShape2", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 20, 20, 200, 200);
var groupShape = sheet.shapes.group([shape1, shape2]);
var shapes = groupShape.all();
Shape[]
组合中的所有形状数组。
▸ allowMove(value?): any
获取或设置是否禁用移动形状。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var state = heart.allowMove();
heart.allowMove(!state);
| Name | Type | Description |
|---|---|---|
value? |
boolean |
是否禁用移动形状的设置。 |
any
如果未设置值,返回是否禁用移动形状的设置。
▸ allowResize(value?): any
获取或设置形状的调整大小模式。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var state = heart.allowResize();
heart.allowResize(GC.Spread.Sheets.Shapes.ResizeMode.aspect);
| Name | Type | Description |
|---|---|---|
value? |
boolean | ResizeMode |
是否禁用调整形状大小的设置。 |
any
如果未设置值,返回是否禁用调整形状大小的设置。
▸ allowRotate(value?): any
获取或设置是否禁用旋转形状。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var state = heart.allowRotate();
heart.allowRotate(!state);
| Name | Type | Description |
|---|---|---|
value? |
boolean |
是否禁用旋转形状的设置。 |
any
如果未设置值,返回是否禁用旋转形状的设置。
▸ alt(value?): any
获取或设置形状的替代文本(用于屏幕阅读器)。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
heart.alt("一个心形");
| Name | Type | Description |
|---|---|---|
value? |
string |
形状的替代文本。 |
any
形状的替代文本。
▸ canPrint(value?): any
获取或设置此形状是否可打印。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var state = heart.canPrint(); // 获取形状是否可打印,默认值为 true.
workbook.print(); // 心形被打印。
heart.canPrint(false);
workbook.print(); // 心形不被打印。
| Name | Type | Description |
|---|---|---|
value? |
boolean |
指示此形状是否可打印的值。 |
any
如果未设置值,返回此形状是否可打印。
▸ dynamicMove(value?): any
获取或设置形状在隐藏或显示、调整大小或移动行或列时是否移动。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var state = heart.dynamicMove();
heart.dynamicMove(!state);
| Name | Type | Description |
|---|---|---|
value? |
boolean |
指示形状在隐藏或显示、调整大小或移动行或列时是否移动的值。 |
any
如果未设置值,返回此形状是否动态移动。
▸ dynamicSize(value?): any
获取或设置形状在隐藏或显示、调整大小或移动行或列时是否改变大小。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var state = heart.dynamicSize();
heart.dynamicSize(!state);
| Name | Type | Description |
|---|---|---|
value? |
boolean |
指示形状在隐藏或显示、调整大小或移动行或列时是否改变大小的值。 |
any
如果未设置值,返回此形状是否动态改变大小。
▸ endColumn(value?): any
获取或设置形状位置的结束列索引。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var n = heart.endColumn();
heart.endColumn(n + 1);
| Name | Type | Description |
|---|---|---|
value? |
number |
形状位置的结束列索引。 |
any
如果未设置值,返回形状位置的结束列索引。
▸ endColumnOffset(value?): any
获取或设置相对于形状结束列的偏移量。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var n = heart.endColumnOffset();
heart.endColumnOffset(0);
| Name | Type | Description |
|---|---|---|
value? |
number |
相对于形状结束列的偏移量。 |
any
如果未设置值,返回相对于形状结束列的偏移量。
▸ endRow(value?): any
获取或设置形状位置的结束行索引。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var n = heart.endRow();
heart.endRow(n + 2);
| Name | Type | Description |
|---|---|---|
value? |
number |
形状位置的结束行索引。 |
any
如果未设置值,返回形状位置的结束行索引。
▸ endRowOffset(value?): any
获取或设置相对于形状结束行的偏移量。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var n = heart.endRowOffset();
heart.endRowOffset(0);
| Name | Type | Description |
|---|---|---|
value? |
number |
相对于形状结束行的偏移量。 |
any
如果未设置值,返回相对于形状结束行的偏移量。
▸ find(name): Shape
在组合形状中通过名称查找形状。
example
var shape1 = activeSheet.shapes.add("heart1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
var shape2 = activeSheet.shapes.add("heart2", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 260, 50, 100, 150);
var groupShape = activeSheet.shapes.group([shape1, shape2]);
var heart1 = groupShape.find("heart1"); // heart1 与 shape1 相等。
| Name | Type | Description |
|---|---|---|
name |
string |
组合形状中要查找的形状名称。 |
若名称属于组合中的形状,则返回该形状实例;否则返回
▸ getFormula(path): string
按路径从形状中获取公式字符串。
example
sheet.name("Sheet1");
sheet.setValue(0, 1, 30);
var shape1 = sheet.shapes.add("myShape1", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 62 * 9, 0, 200, 200);
var shape2 = sheet.shapes.add("myShape2", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 20, 20, 200, 200);
var shape = sheet.shapes.group([shape1, shape2]);
shape.setFormula("rotate", "=Sheet1!B1");
shape.getFormula("rotate");//返回 "=Sheet1!B1"
| Name | Type | Description |
|---|---|---|
path |
string |
可接受公式字符串的路径,可选值包括 "x"、"y"、"width"、"height"、"rotate"。 |
string
按路径从形状中返回的公式字符串。
▸ height(value?): any
获取或设置形状的高度。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var n = heart.height();
heart.height(n + 50);
| Name | Type | Description |
|---|---|---|
value? |
string | number |
形状的高度,可以是数值或公式(以=开头)。 |
any
如果未设置值,返回形状的高度。
▸ hyperlink(value?): void | IHyperlink
获取或设置形状的超链接。
example
var shape = sheet.shapes.add("myShape", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 62 * 9, 0, 200, 200);
shape.hyperlink({url: "http://www.spreadjs.com", target: 0, tooltip: 'goes to SpreadJS'});
| Name | Type | Description |
|---|---|---|
value? |
IHyperlink |
超链接设置。 |
void | IHyperlink
如果未设置值,返回形状当前的超链接设置。
▸ isLocked(value?): any
获取或设置此形状是否被锁定。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var state = heart.isLocked();
heart.isLocked(!state);
| Name | Type | Description |
|---|---|---|
value? |
boolean |
指示此形状是否被锁定的值。 |
any
如果未设置值,返回此形状是否被锁定。
▸ isSelected(value?): any
获取或设置此形状是否被选中。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var state = heart.isSelected();
heart.isSelected(!state);
| Name | Type | Description |
|---|---|---|
value? |
boolean |
指示此形状是否被选中的值。 |
any
如果未设置值,返回此形状是否被选中。
▸ isVisible(value?): any
获取或设置此形状是否可见。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var state = heart.isVisible();
heart.isVisible(!state);
| Name | Type | Description |
|---|---|---|
value? |
boolean |
指示此形状是否可见的值。 |
any
如果未设置值,返回此形状是否可见。
▸ name(value?): any
获取或设置形状的名称。
example
var shape1 = sheet.shapes.add("myShape1", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 62 * 9, 0, 200, 200);
var shape2 = sheet.shapes.add("myShape2", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 20, 20, 200, 200);
var shape = sheet.shapes.group([shape1, shape2]);
shape.name("myGroupShape");
var shapeName = shape.name();
| Name | Type | Description |
|---|---|---|
value? |
string |
形状的名称。 |
any
如果未设置值,返回形状的名称。
▸ remove(shape): void
从组合形状中移除一个形状。
example
var shape1 = activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
var shape2 = activeSheet.shapes.add("shape2", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 260, 50, 100, 150);
var shape3 = activeSheet.shapes.add("shape3", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 260, 100, 150);
var groupShape = activeSheet.shapes.group([shape1, shape2, shape3]);
// 从groupShape中移除shape3。
groupShape.remove(shape3);
| Name | Type | Description |
|---|---|---|
shape |
Shape |
要从组合形状中移除的形状。 |
void
▸ rotate(value?): number | void
获取或设置组合形状的旋转角度。
example
var shape1 = sheet.shapes.add("myShape1", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 62 * 9, 0, 200, 200);
var shape2 = sheet.shapes.add("myShape2", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 20, 20, 200, 200);
var shape = sheet.shapes.group([shape1, shape2]);
shape.rotate(60);
var angle = shape.rotate();
| Name | Type | Description |
|---|---|---|
value? |
string | number |
组合形状的旋转角度,单位为度。可接受数值或公式(以=开头)。 |
number | void
若未传入参数,返回当前旋转角度;否则无返回值。
▸ setFormula(path, formula): void
按路径向形状设置公式字符串。
example
sheet.name("Sheet1");
sheet.setValue(0, 1, 30);
var shape1 = sheet.shapes.add("myShape1", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 62 * 9, 0, 200, 200);
var shape2 = sheet.shapes.add("myShape2", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 20, 20, 200, 200);
var shape = sheet.shapes.group([shape1, shape2]);
shape.setFormula("rotate", "=Sheet1!B1");
| Name | Type | Description |
|---|---|---|
path |
string |
可接受公式字符串的路径,可选值包括 "x"、"y"、"width"、"height"、"rotate"。 |
formula |
string |
公式字符串。 |
void
▸ showHandle(value?): any
获取或设置是否显示形状的控制柄。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var state = heart.showHandle();
heart.showHandle(!state);
| Name | Type | Description |
|---|---|---|
value? |
boolean |
是否显示形状控制柄的设置。 |
any
如果未设置值,返回是否显示形状控制柄的设置。
▸ startColumn(value?): any
获取或设置形状位置的起始列索引。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var n = heart.startColumn();
heart.startColumn(n + 2);
| Name | Type | Description |
|---|---|---|
value? |
number |
形状位置的起始列索引。 |
any
如果未设置值,返回形状位置的起始列索引。
▸ startColumnOffset(value?): any
获取或设置相对于形状起始列的偏移量。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var n = heart.startColumnOffset();
heart.startColumnOffset(0);
| Name | Type | Description |
|---|---|---|
value? |
number |
相对于形状起始列的偏移量。 |
any
如果未设置值,返回相对于形状起始列的偏移量。
▸ startRow(value?): any
获取或设置形状位置的起始行索引。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var n = heart.startRow();
heart.startRow(n + 2);
| Name | Type | Description |
|---|---|---|
value? |
number |
形状位置的起始行索引。 |
any
如果未设置值,返回形状位置的起始行索引。
▸ startRowOffset(value?): any
获取或设置相对于形状起始行的偏移量。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var n = heart.startRowOffset();
heart.startRowOffset(0);
| Name | Type | Description |
|---|---|---|
value? |
number |
相对于形状起始行的偏移量。 |
any
如果未设置值,返回相对于形状起始行的偏移量。
▸ toImageSrc(): string
获取形状的Base64字符串类型的图片源。
example
let shapeImageSrc = sheet.shapes.all()[0].toImageSrc();
string
返回形状的Base64字符串类型的图片源。
▸ toImageSrcAsync(): Promise<string>
获取形状的Base64字符串类型的图片源。
example
let shapeImageSrc = await sheet.shapes.all()[0].toImageSrcAsync();
Promise<string>
返回形状的Base64字符串类型的图片源。
▸ width(value?): any
获取或设置形状的宽度。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var n = heart.width();
heart.width(n + 50);
| Name | Type | Description |
|---|---|---|
value? |
string | number |
形状的宽度,可以是数值或公式(以=开头)。 |
any
如果未设置值,返回形状的宽度。
▸ x(value?): any
获取或设置形状的水平位置。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var n = heart.x();
heart.x(n + 50);
| Name | Type | Description |
|---|---|---|
value? |
string | number |
形状的水平位置,可以是数值或公式(以=开头)。 |
any
如果未设置值,返回形状的水平位置。
▸ y(value?): any
获取或设置形状的垂直位置。
example
var heart = sheet.shapes.add("Shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 60, 200, 160);
var n = heart.y();
heart.y(n + 50);
| Name | Type | Description |
|---|---|---|
value? |
string | number |
形状的垂直位置,可以是数值或公式(以=开头)。 |
any
如果未设置值,返回形状的垂直位置。
▸ zIndex(shapeName, zIndex?): any
获取或设置组合形状中某个形状的z轴层级。
example
// 此示例展示如何在组合形状中使用z轴层级。
var shape1 = activeSheet.shapes.add("shape1", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
var shape2 = activeSheet.shapes.add("shape2", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 150, 50, 100, 150);
var style = shape1.style();
style.fill.color = "red";
shape1.style(style);
var myGroup = activeSheet.shapes.group([shape1, shape2]);
myGroup.zIndex("shape2"); // 返回1
myGroup.zIndex("shape2", 0); // 将shape2的层级设置为0
| Name | Type | Description |
|---|---|---|
shapeName |
string |
形状的名称。 |
zIndex? |
number |
- |
any
若未传入层级值,返回当前层级;否则无返回值。