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

第1步:设置HTML5页面

首先,我们需要在页面中添加对React的引用:

 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>SpreadJS React Demo</title> <script src="https://unpkg.com/react@16/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> </head> </html> 

在这个页面中,我们将使用Babel的预编译版本(称为babel-standalone),因此我们也会添加一个对此的引用:

<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>

最后,添加对Spread.Sheets的引用:

 <script src="http://cdn.grapecity.com/spreadjs/hosted/scripts/gc.spread.sheets.all.11.0.0.min.js"></script> <link rel="stylesheet" type="text/css" href="http://cdn.grapecity.com/spreadjs/hosted/css/gc.spread.sheets.excel2013white.11.0.0.css">

在我们编写任何脚本之前,我们需要定义一个DIV元素来包含Spread实例。我们称之为“root”。

 <div id="root"></div> 

第2步:为Spread.Sheets创建一个React类

接下来,在页面中添加一个脚本元素。我们将把所有的代码放在这里:

 <script type="text/babel"> </script>

然后,为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(
            <div ref="spreadJs" style={{width:'100%',height:'100%'}}>
            

转载于:http://blog.itpub.net/28298702/viewspace-2155120/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值