Spread.Sheets支持一下三种形状类型
基础形状: 基础形状可以单独使用。
线条形状: 线条形状即可以单独使用也可以链接其他基础形状。
分组形状: 分组形状并不是一个真实的形状,但是被用作一个形状的管理者,以便方便快捷的操作一组形状。
使用形状功能需要添加如下的JS文件到文档的Head部分:
你可以使用ShapeCollection类上的API来管理所有的形状:
你可以通过sheet.shapes.add方法创建一个基础形状:
sheet.shapes.add('autoShape', GC.Spread.Sheets.Shapes.AutoShapeType.heart, 100, 50, 100, 150);
你可以通过sheet.shapes.addConnector方法创建一个线条形状:
sheet.shapes.addConnector('connectorShape', GC.Spread.Sheets.Shapes.ConnectorType.elbow, 200, 50, 300, 200);
你可以根据形状的名字来获取或删除一个形状:
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import './styles.css';
import { AppFunc } from './app-func';
import { App } from './app-class';
// 1. Functional Component sample
ReactDOM.render(<AppFunc />, document.getElementById('app'));
// 2. Class Component sample
// ReactDOM.render(<App />, document.getElementById('app'));
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import GC from '@grapecity-software/spread-sheets';
import "@grapecity-software/spread-sheets-shapes";
import '@grapecity-software/spread-sheets-resources-zh';
GC.Spread.Common.CultureManager.culture("zh-cn");
import { SpreadSheets } from '@grapecity-software/spread-sheets-react';
import './styles.css';
import Panel from './panel.jsx';
const Component = React.Component;
function _getElementById(id) {
return document.getElementById(id);
}
export function AppFunc() {
let spread = null;
let autoGenerateColumns = false;
let insertShape = function(e) {
let sheet = 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('', e, x, y);
shape.style().hAlign = 1;
}
let insertConnectShape = function(e) {
let sheet = spread.getActiveSheet(), shapes = sheet.shapes, total = shapes.all().length;
let x = 40 + (total % 2) * 250, y = parseInt(total / 2) * 200 + 20;
shapes.addConnector('', parseInt(e), x, y, x + 200, y + 200);
}
let initSpread = function(value) {
spread = value;
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);
}
return (<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => initSpread(spread)}>
</SpreadSheets>
</div>
<Panel
insertShape={(addShapeType) => { insertShape(addShapeType) }}
insertConnectShape={(addConnectorShapeType) => { insertConnectShape(addConnectorShapeType) }}>
</Panel>
</div>);
}
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import GC from '@grapecity-software/spread-sheets';
import "@grapecity-software/spread-sheets-shapes"
import '@grapecity-software/spread-sheets-resources-zh';
GC.Spread.Common.CultureManager.culture("zh-cn");
import { SpreadSheets } from '@grapecity-software/spread-sheets-react';
import './styles.css';
import Panel from './panel.jsx';
const Component = React.Component;
function _getElementById(id) {
return document.getElementById(id);
}
export class App extends Component {
constructor(props) {
super(props);
this.spread = null;
this.autoGenerateColumns = false;
}
render() {
return (<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => this.initSpread(spread)}>
</SpreadSheets>
</div>
<Panel
insertShape={(addShapeType) => { this.insertShape(addShapeType) }}
insertConnectShape={(addConnectorShapeType) => { this.insertConnectShape(addConnectorShapeType) }}>
</Panel>
</div>);
}
insertShape(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);
shape.style().hAlign = 1;
}
insertConnectShape(addConnectorShapeType) {
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);
}
initSpread(spread) {
this.spread = 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);
}
}
import * as React from 'react';
import GC from '@grapecity-software/spread-sheets';
import "@grapecity-software/spread-sheets-shapes"
const Component = React.Component;
export default class Panel extends Component {
constructor(props) {
super(props);
this.state = {
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)
}
}
render() {
const state = this.state;
const { insertShape,
insertConnectShape
} = this.props;
return (<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={state.addShapeType} onChange={(event) => { this.setState({ addShapeType: event.target.value }); }}>
{state.autoShapeTypeList.map(({ name, value }) => {
return <option value={value} key={name}>{name}</option>
})}
</select>
<input type='button' onClick={() => { insertShape(state.addShapeType) }} value="Add" />
<label for='connectShapeType'>Add Connect Shape: </label>
<select class="shapeSelect" value={state.addConnectorShapeType} onChange={(event) => { this.setState({ addConnectorShapeType: event.target.value }); }}>
{state.connectorTypeList.map(({ name, value }) => {
return <option value={value} key={name}>{name}</option>
})}
</select>
<input type='button' onClick={() => { insertConnectShape(state.addConnectorShapeType) }} value="Add" />
</div>
</div >);
}
}
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;
}
<!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$/zh/react/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- SystemJS -->
<script src="$DEMOROOT$/zh/react/node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('$DEMOROOT$/zh/lib/react/license.js').then(function() {
System.import('./src/app');
});
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
.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;
}
#app{
width: 100%;
height: 100%;
}
(function(global) {
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true,
react: true
},
meta: {
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'@grapecity-software/spread-sheets': 'npm:@grapecity-software/spread-sheets/index.js',
'@grapecity-software/spread-sheets-resources-zh': 'npm:@grapecity-software/spread-sheets-resources-zh/index.js',
'@grapecity-software/spread-sheets-react': 'npm:@grapecity-software/spread-sheets-react/index.js',
'@grapecity-software/spread-sheets-shapes': 'npm:@grapecity-software/spread-sheets-shapes/index.js',
'@grapecity-software/jsob-test-dependency-package/react-components': 'npm:@grapecity-software/jsob-test-dependency-package/react-components/index.js',
'react': 'npm:react/umd/react.production.min.js',
'react-dom': 'npm:react-dom/umd/react-dom.production.min.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'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'jsx'
},
"node_modules": {
defaultExtension: 'js'
},
}
});
})(this);