Overview

SpreadJS includes support for over 180 shapes, including many of the Excel shapes. SpreasJS also provides more advanced functionality using data-driven shapes. For example, you can dynamically generate the shape properties using data from a database or other data source that allows you to create interactive shapes such as for a manufacturing plant floor.

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: You can customize the properties of all shapes using the ShapeBase API: allowMove: Gets or sets whether to disable moving the shape. allowResize: Gets or sets whether to disable resizing the shape. allowRotate: Gets or sets whether to disable rotating the shape. showHandle: Gets or sets whether to show handle of shape. isSelected: Gets or sets whether this shape is selected. width/height: Gets or sets the width or height of the shape. x/y: Gets or sets the horizontal or vertical location of the shape. You can customize the properties of autoShapes using the Shape API: rotate: Gets or sets the rotated angle of the shape (unit in degree). text: Gets or sets the text of the shape. style: Gets or sets the style of the shape. You can customize the properties of connectorShapes using the ConnectorShape API: style: Gets or sets the style of the connector shape.
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread"> </gc-spread-sheets> <shape-panel @insertShape="insertShape1" @updateConnectorShapeStyle="updateConnectorShapeStyle" @insertConnectShape="insertConnectShape" @updateShapeStyle="updateShapeStyle" @updateShapeBorderStyle="updateShapeBorderStyle" :showBorderPanel="showBorderPanel" :showShapeFillPropPanel="showShapeFillPropPanel" :showShapeTxtPanel="showShapeTxtPanel" :showConnectorPropPanel="showConnectorPropPanel"> </shape-panel> </div> </template> <script> import Vue from "vue"; import "@grapecity/spread-sheets-vue"; import "@grapecity/spread-sheets-shapes" import GC from "@grapecity/spread-sheets"; import Panel from './panel.vue'; Vue.config.devtools = true; let App = Vue.extend({ name: "app", data: function () { return { spread: null, showBorderPanel: false, showShapeFillPropPanel: false, showShapeTxtPanel: false, showConnectorPropPanel: false }; }, components: { 'shape-panel': Panel }, mounted() { }, methods: { updateShapeStyle(action, value) { let sheet = this.spread.getActiveSheet(); let activeShape = sheet.shapes.all().filter(function (sp) { return sp.isSelected(); }); if (activeShape.length > 0) { activeShape.forEach((shape) => { if (shape instanceof GC.Spread.Sheets.Shapes.Shape) { this._setShapeStyle(shape, action, value); } }); sheet.repaint(); } }, updateShapeBorderStyle(action, value) { let sheet = this.spread.getActiveSheet(); let activeShape = sheet.shapes.all().filter(function (sp) { return sp.isSelected(); }); if (activeShape) { activeShape.forEach(function (shape) { let shapeStyle = shape.style(); shapeStyle.line[action] = value; shape.style(shapeStyle); }); sheet.repaint(); } }, updateConnectorShapeStyle(action, value) { let sheet = this.spread.getActiveSheet(); let activeShape = sheet.shapes.all().filter(function (sp) { return sp.isSelected() && sp instanceof GC.Spread.Sheets.Shapes.ConnectorShape; }); if (activeShape.length > 0) { activeShape.forEach((shape) => { this._setConnectorShapeStyle(shape, action, value); }); sheet.repaint(); } }, _setConnectorShapeStyle(shape, action, value) { let shapeStyle = shape.style(); let shapeStyleLine = shapeStyle.line; switch (action) { case "beginStyle": { shapeStyleLine.beginArrowheadStyle = value; break; } case "beginWidth": { shapeStyleLine.beginArrowheadWidth = value; break; } case "beginLength": { shapeStyleLine.beginArrowheadLength = value; break; } case "endStyle": { shapeStyleLine.endArrowheadStyle = value; break; } case "endWidth": { shapeStyleLine.endArrowheadWidth = value; break; } case "endLength": { shapeStyleLine.endArrowheadLength = value; break; } } shape.style(shapeStyle); }, _setShapeStyle(shape, action, value) { if (action === 'rotate') { shape.rotate(value); } else if (action === 'text') { shape.text(value); } else { var shapeStyle = shape.style(); if (action === 'background') { shapeStyle.fill.color = value; } else if (action === 'transparency') { shapeStyle.fill.transparency = value; } else if (action === 'color') { shapeStyle.textEffect.color = value; } else if (action === 'transparencyTxt') { shapeStyle.textEffect.transparency = value; } else if (action === 'font') { shapeStyle.textEffect.font = value; } else if (action === 'hAlign') { shapeStyle.textFrame.hAlign = parseInt(value); } else if (action === 'vAlign') { shapeStyle.textFrame.vAlign = parseInt(value); } shape.style(shapeStyle); } }, bindSpreadEvent() { let spread = this.spread, self = this; spread.bind(GC.Spread.Sheets.Events.ShapeSelectionChanged, function () { let sheet = spread.getActiveSheet(); var selectedShape = sheet.shapes.all().filter(function (sp) { return sp.isSelected(); }); var isShapeSelected = false, isConnectorSelected = false; if (selectedShape.length > 0) { selectedShape.forEach((shape) => { if (!isShapeSelected && shape instanceof GC.Spread.Sheets.Shapes.Shape) { isShapeSelected = true; } else if (!isConnectorSelected && shape instanceof GC.Spread.Sheets.Shapes.ConnectorShape) { isConnectorSelected = true; } }); self.setShapePropVisibility(isShapeSelected); self.setConnectorPropVisibility(isConnectorSelected); self.setBorderPropVisibility(true); } else { self.setShapePropVisibility(false); self.setConnectorPropVisibility(false); self.setBorderPropVisibility(false); } }) }, setBorderPropVisibility(isShow) { this.showBorderPanel = isShow; }, setConnectorPropVisibility(isShow) { this.showConnectorPropPanel = isShow; }, setShapePropVisibility(isShow) { this.showShapeTxtPanel = isShow; this.showShapeFillPropPanel = isShow; }, initSpread(spread) { this.spread = spread; spread.getActiveSheet().shapes.add("heart", GC.Spread.Sheets.Shapes.AutoShapeType.heart, 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); this.bindSpreadEvent(); }, insertShape1(addShapeType) { 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); this._setShapeStyle(shape, 'hAlign', 1); }, insertConnectShape(addConnectoShapeType) { 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('', addConnectoShapeType, x, y, x + 200, y + 200); } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <style scoped> .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: lavender; } 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; } </style>
<template> <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" id="'autoShapeType'" v-model.number="addShapeType"> <option v-bind:value="item.value" v-for="item in autoShapeTypeList" :key="item.name">{{ item.name }}</option> </select> <input type='button' @click="insertShape" value="Add" /> <label for='connectShapeType'>Add Connect Shape: </label> <select class="shapeSelect" id="connectShapeType" v-model.number="addConnectorShapeType"> <option v-bind:value="item.value" v-for="item in connectorTypeList" :key="item.name">{{ item.name }}</option> </select> <input type='button' @click='insertConnectShape' value="Add" /> </div> <div id="divideLine" class="divide-line"></div> <div v-show="showBorderPanel" class="option-row"> <label class="title">Shape Border</label> <label>Border Color: </label> <input v-model="borderColor" type="color" /> <input type="button" @click="_handleShapeBorderAction('color', borderColor)" value="Set" /> <label>Border Transparency: </label> <input v-model="borderTransparency" type="text" value="0.5" /> <input type="button" @click="_handleShapeBorderAction('transparency', borderTransparency)" value="Set" /> <label>Border Width: </label> <input v-model="borderWidth" type="number" /> <input type="button" @click="_handleShapeBorderAction('width', borderWidth)" value="Set" /> <label>Border Line Style: </label> <select v-model="borderLineStyle"> <option v-bind:value="item.value" v-for="item in lineDashStyleList" :key="item.name">{{ item.name }}</option> </select> <input type="button" @click="_handleShapeBorderAction('lineStyle', borderLineStyle)" value="Set" /> <label>Border Cap Line Style: </label> <select v-model.number="borderCapType"> <option v-bind:value="item.value" v-for="item in lineCapStyleList" :key="item.name">{{ item.name }}</option> </select> <input type="button" @click="_handleShapeBorderAction('capType', borderCapType)" value="Set" /> <label>Border Join Line Style: </label> <select v-model="borderJoinType"> <option v-bind:value="item.value" v-for="item in lineJoinStyleList" :key="item.name">{{ item.name }}</option> </select> <input type="button" @click="_handleShapeBorderAction('joinType', borderJoinType)" value="Set" /> </div> <div v-show="showShapeFillPropPanel" id="shapeFillProp" class="option-row"> <div class="divide-line"></div> <label class="title">Shape Fill and Rotate</label> <label>Fill Color: </label> <input v-model="background" type="color" /> <input type="button" @click="_handleShapeStyleSetting('background', background)" value="Set" /> <label>Fill Transparency: </label> <input v-model.number="transparency" type="text" /> <input type="button" @click="_handleShapeStyleSetting('transparency', transparency)" value="Set" /> <label for='txtRotate'>Rotate: </label> <input type="number" id="txtRotate" min="0" max="360" v-model="rotate" /> <input type="button" @click="_handleShapeStyleSetting('rotate', rotate)" value="Set" /> </div> <div v-show="showShapeTxtPanel" class="option-row"> <div class="divide-line"></div> <label class="title">Shape Text</label> <label>Text: </label> <textarea v-model="text" type="text" placeholder="Shape text" rows="3"></textarea> <input type="button" @click="_handleShapeStyleSetting('text', text)" value="Set" /> <label>Text Color: </label> <input v-model="textColor" type="color" value="#FFFF00" /> <input type="button" @click="_handleShapeStyleSetting('color', textColor)" value="Set" /> <label>Text Transparency: </label> <input v-model.number="transparencyTxt" type="text" value="0.5" /> <input type="button" @click="_handleShapeStyleSetting('transparencyTxt', transparencyTxt)" value="Set" /> <label>Text Font: </label> <input v-model="font" type="text" /> <input type="button" @click="_handleShapeStyleSetting('font', font)" value="Set" /> <label> Horizontal Align:</label> <select v-model.number="hAlign"> <option v-bind:value="item.value" v-for="item in horizontalAlignList" :key="item.name">{{ item.name }}</option> </select> <input type="button" @click="_handleShapeStyleSetting('hAlign', hAlign)" value="Set" /> <label>Vertical Align:</label> <select v-model.number="vAlign"> <option v-bind:value="item.value" v-for="item in verticalAlignList" :key="item.name">{{ item.name }}</option> </select> <input type="button" @click="_handleShapeStyleSetting('vAlign', vAlign)" value="Set" /> </div> <div v-show="showConnectorPropPanel" class="option-row"> <div class="divide-line"></div> <label class="title">Shape Arrow Head</label> <label for="beginArrowheadStyle">Begin Arrowhead Style:</label> <select v-model="beginStyle" id="beginArrowheadStyle" class="shapeSelect"> <option :value="item.value" v-for="item in arrowHeadStyle" :key="item.name"> {{item.name}}</option> </select> <input @click="_handleConnectorShapeStyleSetting('beginStyle', beginStyle)" type="button" class='arrow-action-button' value="Set" /> <label>Begin Arrowhead Width:</label> <select v-model="beginWidth" class="shapeSelect"> <option :value="item.value" v-for="item in arrowHeadWidthList" :key="item.name"> {{item.name}}</option> </select> <input type="button" @click="_handleConnectorShapeStyleSetting('beginWidth', beginWidth)" class='arrow-action-button' value="Set" /> <label>Begin Arrowhead Length:</label> <select v-model="beginLength" class="shapeSelect"> <option :value="item.value" v-for="item in arrowHeadLengthList" :key="item.name"> {{item.name}}</option> </select> <input type="button" @click="_handleConnectorShapeStyleSetting('beginLength', beginLength)" class='arrow-action-button' value="Set" /> <label for="endArrowheadStyle">End Arrowhead Style:</label> <select v-model="endStyle" id="endArrowheadStyle" class="shapeSelect"> <option :value="item.value" v-for="item in arrowHeadStyle" :key="item.name"> {{item.name}}</option> </select> <input type="button" @click="_handleConnectorShapeStyleSetting('endStyle', endStyle)" class='arrow-action-button' value="Set" /> <label>End Arrowhead Width:</label> <select v-model="endWidth" class="shapeSelect"> <option v-bind:value="item.value" v-for="item in arrowHeadWidthList" :key="item.name">{{ item.name }}</option> </select> <input type="button" @click="_handleConnectorShapeStyleSetting('endWidth', endWidth)" class='arrow-action-button' value="Set" /> <label>End Arrowhead Length:</label> <select v-model="endLength" class="shapeSelect"> <option v-bind:value="item.value" v-for="item in arrowHeadLengthList" :key="item.name">{{ item.name }}</option> </select> <input type="button" @click="_handleConnectorShapeStyleSetting('endLength', endLength)" class='arrow-action-button' value="Set" /> </div> </div> </template> <script> import GC from "@grapecity/spread-sheets"; import "@grapecity/spread-sheets-shapes" export default { props: [ "showBorderPanel", "showShapeFillPropPanel", "showShapeTxtPanel", "showConnectorPropPanel" ], data: function () { let lineCapStyle = { flat: 2, square: 1, round: 0 }; let lineJoinStyle = { round: 0, miter: 1, bevel: 2 }; let lineDashStyle = { solid: 0, squareDot: 1, dash: 2, longDash: 3, dashDot: 4, longDashDot: 5, longDashDotDot: 6, sysDash: 7, sysDot: 8, sysDashDot: 9, dashDotDot: 10 }; let arrowheadLength = { "short": 0, "medium": 1, "long": 2 }; let arrowheadWidth = { "narrow": 0, "medium": 1, "wide": 2 }; let horizontalAlign = { left: 0, center: 1, right: 2 }; let verticalAlign = { top: 0, center: 1, bottom: 2 }; return { rotate: 30, transparency: 0.5, background: "#00A2E8", text: `abcdefgHIJKLMN 12356789 SpreadJSSpreadJS`, textColor: "#FFFF00", transparencyTxt: 0.5, font: "bold 15px Georgia", hAlign: 1, vAlign: 1, borderColor: "#00A2E8", borderTransparency: 0.5, borderWidth: 1, borderLineStyle: 2, borderCapType: 2, borderJoinType: 2, beginStyle: 3, beginWidth: 1, beginLength: 2, endStyle: 3, endWidth: 1, endLength: 2, 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), horizontalAlignList: getEnumList(horizontalAlign), verticalAlignList: getEnumList(verticalAlign), lineCapStyleList: getEnumList(lineCapStyle), lineJoinStyleList: getEnumList(lineJoinStyle), lineDashStyleList: getEnumList(lineDashStyle), arrowHeadLengthList: getEnumList(arrowheadLength), arrowHeadWidthList: getEnumList(arrowheadWidth), arrowHeadStyle: getEnumList(GC.Spread.Sheets.Shapes.ArrowheadStyle) }; }, methods: { insertShape() { this.$emit("insertShape", this.addShapeType); }, insertConnectShape() { this.$emit("insertConnectShape", this.addConnectorShapeType); }, _handleShapeStyleSetting(action, value) { this.$emit("updateShapeStyle", action, value); }, _handleShapeBorderAction(action, value) { this.$emit("updateShapeBorderStyle", action, value); }, _handleConnectorShapeStyleSetting(action, value) { this.$emit("updateConnectorShapeStyle", action, value); } }, mounted() {} } function getEnumList(enumObject) { let names = []; for (var name in enumObject) { if (name === "none" || (parseInt(name, 10)) == name) { continue; } names.push({ name: name, value: enumObject[name] }); } names.sort(function (a, b) { return a.name > b.name ? 1 : -1 }); return names; } </script> <style> </style>
<!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/vue/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/en/vue/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); System.import('$DEMOROOT$/en/lib/vue/license.js'); </script> </head> <body> <div id="app"></div> </body> </html>
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, meta: { '*.css': { loader: 'css' }, '*.vue': { loader: 'vue-loader' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@grapecity/spread-sheets': 'npm:@grapecity/spread-sheets/index.js', '@grapecity/spread-sheets-vue': 'npm:@grapecity/spread-sheets-vue/index.js', '@grapecity/spread-sheets-shapes': 'npm:@grapecity/spread-sheets-shapes/index.js', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js', 'jszip': 'npm:jszip/dist/jszip.js', 'css': 'npm:systemjs-plugin-css/css.js', 'vue': 'npm:vue/dist/vue.min.js', 'vue-loader': 'npm:systemjs-vue-browser/index.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'js' }, rxjs: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' } } }); })(this);