纯干货分享:如何在 React 框架中使用SpreadJS

然后,为Spread.Sheets定义一个React组件,以便我们可以定义一个扩展React.Component的类:

 class ReactSpreadJS extends React.Component{ }

该类需要在其中定义componentDidMount和render函数。componentDidMount函数在组件被挂载后立即被调用,所以我们用它来初始化Spread实例:

 componentDidMount() { //In the DidMount life cycle, we initialize Spread Sheet instance, and the host is defined in the Component template. let spread = new GC.Spread.Sheets.Workbook(this.refs.spreadJs, {sheetCount: 3});  if(this.props.workbookInitialized){ this.props.workbookInitialized(spread); } }

接下来,在渲染函数中定义Spread.Sheets DOM元素:

 render() { //Define the Spread.Sheets DOM template return( 
); }

第3步:为组件创建一个应用程序类

首先,通过App类定义应用程序React组件:

 //Define the application react component. class App extends React.Component{ }

接下来,添加一个您将调用ReactSpreadJS组件的渲染函数:

 render(){ //In the root component, it include one ReactSpreadJS component. return( 
{console.log(spread)}}>
) }

要完成脚本,请告诉React通过使用ReactDOM.render来初始化应用程序:

 ReactDOM.render( //Main entry, initialize application react component. , document.getElementById('root') );

这就是使用React将Spread.Sheets添加到HTML页面所需的全部内容。这只是React和Spread.Sheets的基本使用,但可以轻松扩展。


关于SpreadJS前端表格控件

是基于 HTML5 的 JavaScript 电子表格和网格功能控件,适用于.NET、Java 、Web应用程序、移动端等多种平台的表格数据处理和类Excel功能的表格程序开发。全中文操作界面,零学习成本!便于您在系统开发过程中,更安全的管理Excel 数据,更快捷的完成海量数据交互,更方便的进行数据导出、导入、排序、过滤、增删改查、可视化及Excel 导入/导出等操作。SpreadJS自面世以来,备受华为、中通、中国民航飞行学院、中国平安 、中国能建、浪潮等国内知名企业客户青睐。


分享到:


相關文章: