找回密码
 立即注册

QQ登录

只需一步,快速开始

Lynn.Dou 讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-5-10 11:41  /   查看:2373  /  回复:2
本帖最后由 Lynn.Dou 于 2021-5-31 09:23 编辑

在SpreadJS V14 Update1 之前的版本中,设置表单保护时,允许展开/折叠分组。

SpreadJS V14 Update1 中对表单保护行为做了增强,设置表单保护时,可以通过API控制是否禁用展开/折叠分组。

      -        当工作表受保护且protectOption的allowOutlineRows为false时,行组不能折叠和展开。
      -        当工作表受保护且protectOption的allowOutlineRows为true时,行组可以折叠和展开
      -        当工作表受保护且protectOption的allowOutlineColumns为false时,列组不能折叠和展开。
      -        当工作表受保护且protectOption的allowOutlineColumns为true时,列组可以折叠和展开。
      -        默认情况下,工作表受保护时,allowOutlineRowsallowOutlineColumns为false,也就是说禁止展开/折叠分组。

表单受保护且行列组禁止展开/折叠时,点击展开/折叠按钮,将会触发invalidOperation 事件。
在designer中表现为,弹出错误提示弹框:

image.png367291869.png

示例代码:  
  1. var spread = new GC.Spread.Sheets.Workbook(DOC);
  2.    var activeSheet = spread.getActiveSheet();
  3.    activeSheet.suspendPaint();
  4.    activeSheet.setRowCount(34);
  5.    activeSheet.setValue(0,0,"Western");
  6.    activeSheet.setValue(0,1,"Western");
  7.    activeSheet.setValue(0,2,"Western");
  8.    activeSheet.setValue(1,0,"A");
  9.    activeSheet.setValue(1,1,"B");
  10.    activeSheet.setValue(1,2,"C");
  11.    activeSheet.setValue(2,0,"A");
  12.    activeSheet.setValue(2,1,"B");
  13.    activeSheet.setValue(2,2,"C");
  14.    activeSheet.rowOutlines.group(0,2);
  15.    activeSheet.columnOutlines.group(0,1);
  16.    activeSheet.options.isProtected = true;
  17.    sheet.options.protectionOptions.allowOutlineColumns= false;
  18.    sheet.options.protectionOptions.allowOutlineRows= false;
  19.    activeSheet.resumePaint();      
  20.    spread.bind(Sheets.Events.InvalidOperation, (e, args) => {
  21.        if(args.invalidType === GC.Spread.Sheets.InvalidOperationType.groupProtected){
  22.            alert(args.message)
  23.        }
  24.    });
复制代码




2 个回复

倒序浏览
hjkl
初级会员   /  发表于:2021-5-30 11:38:08
沙发
你好  貌似没有起作用  ,  附件是测试代码

test0529.rar

830 Bytes, 下载次数: 47

评分

参与人数 1金币 +666 收起 理由
Lynn.Dou + 666 很给力!

查看全部评分

回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-5-31 09:25:53
板凳
您好,技术博客中API有误,感谢您的指出。
将代码修改为以下即可:
  1. //activeSheet.options.protectionOptions.allowOperateOutlineColumn = true;
  2.             activeSheet.options.protectionOptions.allowOutlineRows = true;
  3.                         //activeSheet.options.protectionOptions.allowOperateOutlineRow = true;
  4.             activeSheet.options.protectionOptions.allowOutlineColumns = true;
复制代码
具体您也可以参考学习指南:
https://demo.grapecity.com.cn/sp ... t/protection/purejs
image.png440587157.png
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部