找回密码
 立即注册

QQ登录

只需一步,快速开始

470539167

注册会员

9

主题

13

帖子

191

积分

注册会员

积分
191

[已处理] 获取excel数据

470539167
注册会员   /  发表于:2019-5-20 18:11  /   查看:2426  /  回复:3
本帖最后由 470539167 于 2019-5-22 11:01 编辑

我可能描述的不准确,您按照我的步骤做一次,我无论是使用getText还是getValue都是一样的报错1、import一个带有数据的excel文档
2、直接点击按钮 提交数据 (代码如下)
image.png858424682.png

结果报错
image.png408018187.png

我的目的就是想获取Excel中的某个单元格的原始数据
附件内有demo可以直接使用





image.png752409362.png

demo.zip

34.55 KB, 下载次数: 73

3 个回复

倒序浏览
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2019-5-20 23:12:54
沙发
请使用getValue获取单元格数据:

https://demo.grapecity.com.cn/sp ... sheet~getValue.html
回复 使用道具 举报
470539167
注册会员   /  发表于:2019-5-21 09:07:18
板凳
KevinChen 发表于 2019-5-20 23:12
请使用getValue获取单元格数据:

https://demo.grapecity.com.cn/spreadjs/help/v12/content/webframe.h ...

我试的还是一样报错,我修改了问题您再看一下,我只是想获取excel中某个单元格的原始数据
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2019-5-21 15:52:46
地板
您好,您在代码中先获取到了ActiveSheet,然后又执行了fromJSON方法,

这会导致获取到的sheet被销毁,如图:

image.png444001159.png

应该把getActiveSheet的调用放到getValue前,如下代码所示:

  1. window.onload = function () {
  2.             var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
  3.             // spread.fromJSON(jsonData);
  4.             var excelIo = new GC.Spread.Excel.IO();


  5.             document.getElementById('loadExcel').onclick = function () {
  6.                 var excelFile = document.getElementById("fileDemo").files[0];
  7.                 var password = document.getElementById('password').value;
  8.                 // here is excel IO API
  9.                 excelIo.open(excelFile, function (json) {
  10.                     var workbookObj = json;
  11.                     spread.fromJSON(workbookObj);
  12.                 }, function (e) {
  13.                     // process error
  14.                     alert(e.errorMessage);
  15.                     if (e.errorCode === 2/*noPassword*/ || e.errorCode === 3 /*invalidPassword*/) {
  16.                         document.getElementById('password').onselect = null;
  17.                     }
  18.                 }, { password: password });
  19.             };
  20.             document.getElementById('saveExcel').onclick = function () {

  21.                 var fileName = document.getElementById('exportFileName').value;
  22.                 var password = document.getElementById('password').value;
  23.                 if (fileName.substr(-5, 5) !== '.xlsx') {
  24.                     fileName += '.xlsx';
  25.                 }

  26.                 var json = spread.toJSON();

  27.                 // here is excel IO API
  28.                 excelIo.save(json, function (blob) {
  29.                     saveAs(blob, fileName);
  30.                 }, function (e) {
  31.                     // process error
  32.                     console.log(e);
  33.                 }, { password: password });

  34.             };

  35.             //保存数据
  36.             document.getElementById('saveData').onclick = function () {
  37.                                 var sheet = spread.getActiveSheet();
  38.                 var cell = sheet.getValue(0, 0);
  39.                 console.log(cell);
  40.                 //获取数据
  41.                 // var cell = sheet.getText(0, 0);
  42.                 // console.log(cell)
  43.                 // 获取原数据
  44.                 // var data = spread.toJSON();
  45.                 // console.log(data.sheets['工作表1']);
  46.             }
  47.         };
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部