SpreadJS provides the following three shape types
AutoShape: the autoShape can be used stand-alone.
ConnectorShape: the connector shape can be used stand-along or connected to other shape.
GroupShape: the group shape is not a real shape but used as a manager to process with a group of shapes easily and quickly.
To use the shape feature, add the JS file link into the document's head section:
You can manage all shapes in a sheet using the ShapeCollection API:
You can create a autoShape with the sheet.shapes.add method, as shown below:
You can create a connectorShape with the sheet.shapes.addConnector method, as shown below:
You can get/remove a shape with name using the following code:
import { Component, NgModule, enableProdMode } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { SpreadSheetsModule } from '@mescius/spread-sheets-angular';
import GC from '@mescius/spread-sheets';
import "@mescius/spread-sheets-shapes"
import './styles.css';
function getEnumList(enumObject: object) {
let names = [];
for (var name in enumObject) {
if (name === "none" || (parseInt(<any>name, 10)) == <any>name) {
continue;
}
names.push({
name: name,
value: enumObject[name]
});
}
names.sort(function(a, b) {
return a.name > b.name ? 1 : -1
});
return names;
}
@Component({
selector: 'app-component',
templateUrl: 'src/app.component.html'
})
export class AppComponent {
spread: GC.Spread.Sheets.Workbook;
hostStyle = {
width: 'calc(100% - 280px)',
height: '100%',
overflow: 'hidden',
float: 'left'
};
addShapeType = GC.Spread.Sheets.Shapes.AutoShapeType.actionButtonBackorPrevious;
addConnectorShapeType = GC.Spread.Sheets.Shapes.ConnectorType.elbow;
autoShapeTypeList = getEnumList(GC.Spread.Sheets.Shapes.AutoShapeType);
connectorTypeList = getEnumList(GC.Spread.Sheets.Shapes.ConnectorType);
initSpread($event: any) {
let spread = this.spread = $event.spread;
spread.getActiveSheet().shapes.add("rectangle", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 40, 20, 150, 150);
let lineShape = spread.getActiveSheet().shapes.addConnector("line", GC.Spread.Sheets.Shapes.ConnectorType.straight, 290, 20, 420, 170);
let lineShapeStyle = lineShape.style();
lineShapeStyle.line.width = 8;
lineShape.style(lineShapeStyle);
}
insertShape(addShapeType: GC.Spread.Sheets.Shapes.AutoShapeType) {
let sheet = this.spread.getActiveSheet(),
shapes = sheet.shapes,
total = shapes.all().length;
let x = 40 + (total % 2) * 250,
y = parseInt(total / 2 + '') * 200 + 20;
let shape = shapes.add('', addShapeType, x, y);
shape.style().hAlign = 1;
}
insertConnectShape(addConnectorShapeType: GC.Spread.Sheets.Shapes.ConnectorType) {
// addConnectorShapeType = parseInt(addConnectorShapeType, 10);
let sheet = this.spread.getActiveSheet(), shapes = sheet.shapes, total = shapes.all().length;
let x = 40 + (total % 2) * 250, y = parseInt(total / 2 + '') * 200 + 20;
shapes.addConnector('', parseInt(addConnectorShapeType), x, y, x + 200, y + 200);
}
}
@NgModule({
imports: [BrowserModule, SpreadSheetsModule, FormsModule],
declarations: [AppComponent],
exports: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/angular/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- Polyfills -->
<script src="$DEMOROOT$/en/angular/node_modules/core-js/client/shim.min.js"></script>
<script src="$DEMOROOT$/en/angular/node_modules/zone.js/fesm2015/zone.min.js"></script>
<!-- SystemJS -->
<script src="$DEMOROOT$/en/angular/node_modules/systemjs/dist/system.js"></script>
<script src="systemjs.config.js"></script>
<script>
// workaround to load 'rxjs/operators' from the rxjs bundle
System.import('rxjs').then(function (m) {
System.import('@angular/compiler');
System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators));
System.import('$DEMOROOT$/en/lib/angular/license.ts');
System.import('./src/app.component');
});
</script>
</head>
<body>
<app-component></app-component>
</body>
</html>
<div class="sample-tutorial">
<gc-spread-sheets [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event)">
</gc-spread-sheets>
<div class="options-container">
<div class="option-row">
Try selecting a shape from either of the drop-down menus and click the ‘Add’ button to add that shape to the Spread instance.
</div>
<div class="option-row">
<label for='autoShapeType'>Add Shape: </label>
<select class="shapeSelect" [value]="addShapeType|number" [(ngModel)]="addShapeType">
<option *ngFor="let item of autoShapeTypeList" [value]="item.value">
{{item.name}}
</option>
</select>
<input type='button' (click)="insertShape(addShapeType)" value="Add" />
<label for='connectShapeType'>Add Connect Shape: </label>
<select class="shapeSelect" [value]="addConnectorShapeType|number" [(ngModel)]="addConnectorShapeType">
<option *ngFor="let item of connectorTypeList" [value]="item.value">
{{item.name}}
</option>
</select>
<input type='button' (click)='insertConnectShape(addConnectorShapeType)' value="Add" />
</div>
</div>
</div>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 280px);
height: 100%;
overflow: hidden;
float: left;
}
.options-container {
float: right;
width: 280px;
padding: 12px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
.option-row {
font-size: 14px;
padding-left: 5px;
}
.divide-line {
width: 100%;
height: 1px;
background: #cbcbcb;
margin-top: 10px;
margin-bottom: 3px;
}
.title {
text-align: center;
font-weight: bold;
}
label {
display: block;
margin-top: 15px;
margin-bottom: 5px;
}
p {
padding: 2px 10px;
background-color: #F4F8EB;
}
input {
width: 160px;
margin-left: 10px;
display: inline;
}
input[type=button] {
width: 50px;
margin-left: 1px;
}
select {
width: 160px;
margin-left: 10px;
display: inline;
}
textarea {
width: 160px;
margin-left: 10px;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
(function (global) {
System.config({
transpiler: 'ts',
typescriptOptions: {
tsconfig: true
},
meta: {
'typescript': {
"exports": "ts"
},
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'core-js': 'npm:core-js/client/shim.min.js',
'zone': 'npm:zone.js/fesm2015/zone.min.js',
'rxjs': 'npm:rxjs/dist/bundles/rxjs.umd.min.js',
'@angular/core': 'npm:@angular/core/fesm2022',
'@angular/common': 'npm:@angular/common/fesm2022/common.mjs',
'@angular/compiler': 'npm:@angular/compiler/fesm2022/compiler.mjs',
'@angular/platform-browser': 'npm:@angular/platform-browser/fesm2022/platform-browser.mjs',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/fesm2022/platform-browser-dynamic.mjs',
'@angular/common/http': 'npm:@angular/common/fesm2022/http.mjs',
'@angular/router': 'npm:@angular/router/fesm2022/router.mjs',
'@angular/forms': 'npm:@angular/forms/fesm2022/forms.mjs',
'jszip': 'npm:jszip/dist/jszip.min.js',
'typescript': 'npm:typescript/lib/typescript.js',
'ts': './plugin.js',
'tslib':'npm:tslib/tslib.js',
'css': 'npm:systemjs-plugin-css/css.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js',
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-shapes': 'npm:@mescius/spread-sheets-shapes/index.js',
'@mescius/spread-sheets-angular': 'npm:@mescius/spread-sheets-angular/fesm2020/mescius-spread-sheets-angular.mjs',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
},
"node_modules": {
defaultExtension: 'js'
},
"node_modules/@angular": {
defaultExtension: 'mjs'
},
"@mescius/spread-sheets-angular": {
defaultExtension: 'mjs'
},
'@angular/core': {
defaultExtension: 'mjs',
main: 'core.mjs'
}
}
});
})(this);