If you enter a range in a formula, the range indicator is displayed. You can use the mouse to click and select a range.
Use the Function class to add your own function. For example:
You can also get the function description as shown below:
You can change the in-cell across sheet formula textbox and its popup elements by modify the css definition.
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 GC from '@mescius/spread-sheets';
import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react';
import './styles.css';
export function AppFunc() {
let initSpread = function (spread) {
let fbx = new GC.Spread.Sheets.FormulaTextBox.FormulaTextBox(document.getElementById('formulaBar'));
fbx.workbook(spread);
spread.suspendPaint();
let sheet2 = spread.sheets[1];
sheet2.setArray(0, 0, [[1, 4, 7], [2, 5, 8], [3, 6, 9]]);
let sheet = spread.sheets[0];
sheet.options.allowCellOverflow = true;
sheet.setValue(1, 2, "A helpful text box is displayed when typing any formula in a cell or the area above the sheet.");
sheet.setValue(2, 2, "For example: =sum(1,2,3)");
for (let i = 5; i < 35; i++) {
for (let j = 1; j < 15; j++) {
sheet.setValue(i, j, i * j);
}
}
// used to help show table support feature
sheet.tables.add("Table1", 4, 7, 5, 4);
for (let c = 7; c <= 10; c++) {
sheet.setColumnWidth(c, 90);
}
sheet.setFormula(3, 0, "Table1[[#Headers],[Column2]]");
// used to help show custom name support feature
sheet.addCustomName("RangeB6C9", "$B$6:$C$9", 0, 0);
sheet.addCustomName("Range2", "SUM($C$11:$D$14)", 0, 0);
sheet.setFormula(4, 0, "AVERAGE(RangeB6C9)");
// used to help show multi supported reference types
let formula = "SUM(B6:C9,E6:F9,Table1[#Data],Range2,F11:J14,D16:I17)";
sheet.setActiveCell(1, 0);
sheet.getCell(1, 0).formula(formula);
fbx.text("=" + formula);
// used to help show cross sheet reference
sheet.setFormula(5, 0, "SUM(sheet2!A1:C3)");
sheet.getRange(1, 0, 5, 1).foreColor("green");
spread.resumePaint();
}
return (<div class="sample-tutorial">
<div class="demo-options">
<div class="option-row">
<div id="formulaBar" contentEditable="true" spellCheck="false" style={{ fontFamily: "Calibri", border: "1px solid #808080", width: "100%", boxSizing: "border-box" }}></div>
</div>
</div>
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => initSpread(spread)}>
<Worksheet>
</Worksheet>
<Worksheet>
</Worksheet>
</SpreadSheets>
</div>
</div>);
}
import * as React from 'react';
import GC from '@mescius/spread-sheets';
import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react';
import './styles.css';
const Component = React.Component;
export class App extends Component {
render() {
return <div class="sample-tutorial">
<div class="demo-options">
<div class="option-row">
<div id="formulaBar" contentEditable="true" spellCheck="false" style={{fontFamily: "Calibri", border: "1px solid #808080", width: "100%", boxSizing: "border-box"}}></div>
</div>
</div>
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread=>this.initSpread(spread)}>
<Worksheet>
</Worksheet>
<Worksheet>
</Worksheet>
</SpreadSheets>
</div>
</div>;
}
initSpread(spread) {
let fbx = new GC.Spread.Sheets.FormulaTextBox.FormulaTextBox(document.getElementById('formulaBar'));
fbx.workbook(spread);
spread.suspendPaint();
let sheet2 = spread.sheets[1];
sheet2.setArray(0, 0, [[1, 4, 7], [2, 5, 8], [3, 6, 9]]);
let sheet = spread.sheets[0];
sheet.options.allowCellOverflow = true;
sheet.setValue(1, 2, "A helpful text box is displayed when typing any formula in a cell or the area above the sheet.");
sheet.setValue(2, 2, "For example: =sum(1,2,3)");
for (let i = 5; i < 35; i++) {
for (let j = 1; j < 15; j++) {
sheet.setValue(i, j, i * j);
}
}
// used to help show table support feature
sheet.tables.add("Table1", 4, 7, 5, 4);
for (let c = 7; c <= 10; c++) {
sheet.setColumnWidth(c, 90);
}
sheet.setFormula(3, 0, "Table1[[#Headers],[Column2]]");
// used to help show custom name support feature
sheet.addCustomName("RangeB6C9", "$B$6:$C$9", 0, 0);
sheet.addCustomName("Range2", "SUM($C$11:$D$14)", 0, 0);
sheet.setFormula(4, 0, "AVERAGE(RangeB6C9)");
// used to help show multi supported reference types
let formula = "SUM(B6:C9,E6:F9,Table1[#Data],Range2,F11:J14,D16:I17)";
sheet.setActiveCell(1, 0);
sheet.getCell(1, 0).formula(formula);
fbx.text("=" + formula);
// used to help show cross sheet reference
sheet.setFormula(5, 0, "SUM(sheet2!A1:C3)");
sheet.getRange(1, 0, 5, 1).foreColor("green");
spread.resumePaint();
}
}
<!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/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- SystemJS -->
<script src="$DEMOROOT$/en/react/node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('$DEMOROOT$/en/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: 100%;
height: calc(100% - 20px);
overflow: hidden;
float: left;
}
body {
position: absolute;
margin: 0;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
#app {
height: 100%;
}
.gc-across-sheet-ftb {
z-index: -1 !important;
}
.gc-across-sheet-func-popup {
z-index: -1 !important;
}
(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: {
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-react': 'npm:@mescius/spread-sheets-react/index.js',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/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);