如何实现SpreadJS的纯前端Excel导入导出

  • 格式:pdf
  • 大小:218.88 KB
  • 文档页数:2

2. 初始化 Workbook 实例和 ExcelIO 实例。
var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss')); var excelIo = new GC.Spread.Excel.IO();
3. 接下来你就可以使用 open 方法将 excel 文件导入为 spread json,使 用 save 方法将 spread json 导出为 excel 文件。 例如:
//export Spread.Sheets json to excel file excelio.save(json, function (blob) { //do whatever you want with blob //such as you can save it }, function (e) { //process error console.log(e); });
4 同时,你还打开或保存一个带有密码保护的 excel 文件,只需要在 open 和 save 方法中传入参数 options{password:xxxx}即可。例如:
//import excel file to Spread.Sheets json excelIo.open(excelFile, function (json) { var workbookObj = json; workbook.fromJSON(workbookObj); }, function (e) { // process error console.log(e); },{password:xxxx}); //export Spread.Sheets json to excel file excelio.save(json, function (blob) { //do whatever you want with blob //such as you can save it }, function (e) { //process error console.log(e); },{password:xxxx});
效果展示:
//import excel file to Spread.Sheets json excelIo.open(excelFile, function (json) { var workbookObj = json; workbook.fromJSON(workbookObj); }, function (e) { // process error console.log(e); });
如何实现 SpreadJS 的纯前端 Excel 导入导出
本文主要介绍了如何实现 SpreadJS 的纯前端 Excel 导入导出。
前端导入导出支持将 Spread json 导出为 excel 文件(.xlsx)和将 excel 文件导入为 Spread json. 1. 使用前端导入导出, 你需要将相关的 js 文件添加的 document 的 head 区域。 例如:
<head> ... <script src='.../spreadjs/spread.sheets.all.x.xx.xxxxx.x.min.js' type='text/javascript'></script> <script src='.../spreadjs/pluggable/gc.spread.excelio.x.xx.xxxxx.x.min.js' type='text/javascript'></script> </head>