react 代码
- import * as React from 'react';
- import * as ReactDOM from 'react-dom';
- import '@grapecity/spread-sheets-resources-zh';
- GC.Spread.Common.CultureManager.culture("zh-cn");
- import GC from '@grapecity/spread-sheets';
- import { SpreadSheets, Worksheet, Column } from '@grapecity/spread-sheets-react';
- import './styles.css';
- const Component = React.Component;
- function _getElementById(id) {
- return document.getElementById(id);
- }
- class App extends Component {
- constructor(props) {
- super(props);
- this.spread = null;
- this.spread2 = null;
- this.import_noFormula = false;
- this.import_noStyle = false;
- this.import_rowHeaders = false;
- this.import_columnHeaders = false;
- this.import_donotrecalculateafterload = false;
- this.noFormula = false;
- this.noStyle = false;
- this.SaveCustomRowHeaders = false;
- this.SaveCustomColumnHeaders = false;
- }
- onClickType(){
- alert(11)
- }
- render() {
- return <div class="sample-tutorial">
- <div class="sample-spreadsheets-container">
- <label style={{ font: 'bold 10pt arial' }}>ToJson:</label>
- <div class="sample-spreadsheets">
- <SpreadSheets workbookInitialized={spread => this.initSpread(spread)}>
- <Worksheet></Worksheet>
- </SpreadSheets>
- </div>
- <br />
- <label style={{ font: 'bold 10pt arial' }}>FromJson:</label>
- <div class="sample-spreadsheets">
- <SpreadSheets workbookInitialized={spread => this.initSpread2(spread)}>
- <Worksheet></Worksheet>
- </SpreadSheets>
- </div>
- </div>
- <div className="options-container">
- <div style={{ width: '290px' }}>
- <label>This serializes the first Spread instance to a JSON object, and then deserializes that object into the second Spread instance.</label>
- <div className="option-row">
- <input type="button" defaultValue="系列化" id="fromtoJsonBtn" onClick={e => this.serialization(e)} />
- </div>
- </div>
- </div>
- </div>;
- }
- initSpread(spread) {
- this.spread = spread;
- let sheet = spread.getSheet(0);
- var spreadNS = GC.Spread.Sheets;
- sheet.suspendPaint();
- sheet.setColumnWidth(0, 300);
- let style = new GC.Spread.Sheets.Style();
- style.cellButtons = [
- {
- caption: "按钮1",
- buttonBackColor: "#82BC11",
- command: (sheet, row, col, option) => {
- this.onClickType()
- }
- },
- {
- caption: "按钮2",
- buttonBackColor: "#82BC00",
- command: (sheet, row, col, option) => {
- this.onClickType()
- }
- }
- ];
- sheet.setStyle(0, 0, style);
- sheet.resumePaint();
- }
- initSpread2(spread) {
- this.spread2 = spread;
- }
- serialization(e) {
- //ToJson
- var spread1 = this.spread;
- var jsonStr = JSON.stringify(spread1.toJSON());
- //FromJson
- var spread2 = this.spread2;
- spread2.fromJSON(JSON.parse(jsonStr));
- }
- }
- ReactDOM.render(<App />, _getElementById('app'));
复制代码
|