请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册

QQ登录

只需一步,快速开始

helxsz

注册会员

4

主题

5

帖子

23

积分

注册会员

积分
23
  • 95

    金币

  • 4

    主题

  • 5

    帖子

helxsz
注册会员   /  发表于:2022-4-3 04:02  /   查看:2148  /  回复:1
1金币


先初始化,SelectionChanged 可以作用,
        initSpread(spread) {
            this.spread = spread;
            let spreadNS = GC.Spread.Sheets;
            let self = this;
            sheet = spread.sheets[0];
            sheet.suspendPaint();

            sheet.bind(spreadNS.Events.SelectionChanged, function () {
                let activeCell = sheet.getSelections()[0];
                let path = sheet.getBindingPath(activeCell.row, activeCell.col);
                self.path = path || "";
                let bindingitems = self.seachBindingInfoByKey(self.path);
                console.log('click',self.path,bindingitems);
                self.activeCell = activeCell;
                if(self.allowEditting) self.standardDialogVisible = true;
            });
            sheet.resumePaint();
}

后加载excel, SelectionChanged就没有反应了

        getexcel2(bindingResult){

            var excelIo = new IO();
            var excelFilePath = bindingResult.filepath;
            var xhr = new XMLHttpRequest();
            xhr.open('GET', excelFilePath, true);
            xhr.responseType = 'blob';
            var self = this;
            xhr.onload = function(e) {
               if (this.status == 200) {
               // get binary data as a response
               var blob = this.response;
               // convert Excel to JSON
               console.log(blob);
               excelIo.open(blob, function (json) {
               var workbookObj = json;
               self.spread.fromJSON(workbookObj);


               }, function (e) {
            alert(e.errorMessage);
            }, {});
            }
            }
            xhr.send();

        },


后面尝试,重新绑定 SelectionChanged event, 但还不管用

        getexcel2(bindingResult){

            var excelIo = new IO();
            var excelFilePath = bindingResult.filepath;
            var xhr = new XMLHttpRequest();
            xhr.open('GET', excelFilePath, true);
            xhr.responseType = 'blob';
            var self = this;
            xhr.onload = function(e) {
               if (this.status == 200) {
               // get binary data as a response
               var blob = this.response;
               // convert Excel to JSON
               console.log(blob);
               excelIo.open(blob, function (json) {
               var workbookObj = json;
               self.spread.fromJSON(workbookObj);


              // 重新绑定 SelectionChanged event, 但还不管用
              let spreadNS = GC.Spread.Sheets;
              let sheet = self.spread.sheets[0];
              sheet.suspendPaint();
              sheet.bind(spreadNS.Events.SelectionChanged, function () {
                  let activeCell = sheet.getSelections()[0];
                  let path = sheet.getBindingPath(activeCell.row, activeCell.col);
                  self.path = path || "";
                  let bindingitems = self.seachBindingInfoByKey(self.path);
                  console.log('click',self.path,bindingitems);
                  self.activeCell = activeCell;
                  if(self.allowEditting) self.standardDialogVisible = true;
              });
            sheet.resumePaint();



               }, function (e) {
            alert(e.errorMessage);
            }, {});
            }
            }
            xhr.send();

        },

最佳答案

查看完整内容

您好, SelectionChanged事件是绑定在具体的某个工作簿某个表单上的。 导入excel文件后,表示重新加载了一个新的工作簿,所以spread需要重新获取, 相应的excel文件也需要重新获取后,再次绑定SelectionChanged事件。

1 个回复

倒序浏览
最佳答案
最佳答案
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2022-4-3 04:02:38
来自 2#
您好,
SelectionChanged事件是绑定在具体的某个工作簿某个表单上的。
导入excel文件后,表示重新加载了一个新的工作簿,所以spread需要重新获取,
相应的excel文件也需要重新获取后,再次绑定SelectionChanged事件。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部