找回密码
 立即注册

QQ登录

只需一步,快速开始

KID1412

注册会员

3

主题

8

帖子

27

积分

注册会员

积分
27
  • 597

    金币

  • 3

    主题

  • 8

    帖子

最新发帖
KID1412
注册会员   /  发表于:2021-9-22 16:56  /   查看:1432  /  回复:4
本帖最后由 KID1412 于 2021-9-22 17:02 编辑

想要实现的功能页面刚进来的时候读取服务器的 excle 模板进行展示

我自己的思路
通过 xmr 获取到 excle 文件,转化为文件流,调用Excel.IO,对文件进行导入。

参考链接:
https://demo.grapecity.com.cn/spreadjs/help/api/GC.Spread.Excel.IO.html
https://demo.grapecity.com.cn/spreadjs/help/api/GC.Spread.Sheets.Designer.Designer.html

遇到的问题

1. 目前使用的是 react 的 Designer 组件,代码不知道怎么写

2. SpreadSheets 有 workbookInitialized 的初始化api。但是 Designer api 不太找的到,目前的参考链接是:https://demo.grapecity.com.cn/spreadjs/help/api/GC.Spread.Sheets.Designer.html。是在这里找吗?   api 太多了,一时不知道怎么快速找到想要的代码

我上述思路是正确的吗,期望得到简单的代码描述

我的代码
  1. import '@grapecity/spread-sheets-resources-zh';
  2. import '@grapecity/spread-sheets-designer-resources-cn';
  3. import * as GC from '@grapecity/spread-sheets';
  4. import { Designer } from '@grapecity/spread-sheets-designer-react';
  5. import '@grapecity/spread-sheets-designer/styles/gc.spread.sheets.designer.min.css';
  6. import '@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css';

  7. GC.Spread.Common.CultureManager.culture('zh-cn')
复制代码
  1. const renderSpreadJs = () => (
  2.   <div style={hostStyle}>
  3.    <Designer config={customConfig} designerInitialized={(designer) => { getDesigner(designer); }} styleInfo={{ width: '1500px', height: '80vh' }}></Designer>
  4.       {/* <SpreadSheets workbookInitialized={(spread) => initSpread(spread)}></SpreadSheets> */}
  5.     </div>
  6.   );
复制代码



4 个回复

倒序浏览
KID1412
注册会员   /  发表于:2021-9-22 16:59:12
沙发
本帖最后由 KID1412 于 2021-9-22 17:01 编辑
  1.   const renderSpreadJs = () => (
  2.     <div style={hostStyle}>
  3.       <Designer
  4.         styleInfo={{ width: '1500px', height: '80vh' }}
  5.       ></Designer>
  6.       {/* <SpreadSheets workbookInitialized={(spread) => initSpread(spread)}></SpreadSheets> */}
  7.     </div>
  8.   );
复制代码
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-9-22 17:41:02
板凳
你好,关于如何在React中引入SpreadJS可以参考附件的demo,另外如果想要在加载表单的时候加载服务器的Excel文件可以参考下面的代码
  1. var excelIo = new GC.Spread.Excel.IO();
  2.     var excelFilePath = 'resources/Excel/importExcel.xlsx';
  3.     var xhr = new XMLHttpRequest();
  4.     xhr.open('GET', excelFilePath, true);
  5.     xhr.responseType = 'blob';   
  6.     xhr.onload = function(e) {
  7.       if (this.status == 200) {
  8.         // get binary data as a response
  9.         var blob = this.response;
  10.         // convert Excel to JSON
  11.         excelIo.open(blob, function (json) {
  12.             var workbookObj = json;
  13.             spread.fromJSON(workbookObj);
  14.         }, function (e) {
  15.             // process error
  16.             alert(e.errorMessage);
  17.         }, {});
  18.       }
  19.     };
  20.      
  21.     xhr.send();
复制代码
更多信息可以参考这篇技术文章
https://gcdn.grapecity.com.cn/fo ... hread&tid=37389

另外,我们有一个新手训练营,您也可以了解一下,有助于学习SpreadJS
https://gcdn.grapecity.com.cn/fo ... peid%26typeid%3D343

ReactSample.zip

505.45 KB, 下载次数: 29

回复 使用道具 举报
KID1412
注册会员   /  发表于:2021-9-22 17:44:07
地板
Derrick.Jiao 发表于 2021-9-22 17:41
你好,关于如何在React中引入SpreadJS可以参考附件的demo,另外如果想要在加载表单的时候加载服务器的Excel ...

好的,谢谢!
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-9-22 18:00:22
5#

不用客气,有新问题欢迎开新帖交流~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部