找回密码
 立即注册

QQ登录

只需一步,快速开始

wangqgsunway

中级会员

84

主题

224

帖子

740

积分

中级会员

积分
740
wangqgsunway
中级会员   /  发表于:2019-3-7 15:19  /   查看:3029  /  回复:1
获取绑定数据源的所有单元格,有的不只是单元格的绑定,还有动态列表的绑定
下面附上demo

右边的所有数据源都需要获取到 包括动态行的数据源

右边的所有数据源都需要获取到 包括动态行的数据源

demo.rar

8.6 KB, 下载次数: 106

1 个回复

倒序浏览
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2019-3-8 10:50:52
沙发
您好,看了您的Demo,Demo中包含有绑定的单元格和表格,

获取绑定单元格的方法,之前已经讨论过,可以使用getBindingPath即可获取,

关于获取绑定表格的方法,我补充了一下之前贴出的示例。

实际上,表格绑定路径的获取,需要先获取到表格对象,然后调用range()方法获取表格所在区域,

对应的,调用table.bindingPath()可以获取到这部分区域绑定的数据源,请参考完整代码:

  1. var spread = GC.Spread.Sheets.findControl("ss");

  2. function ngAfterViewInit() {
  3.   // // 工作簿
  4.   const source = new GC.Spread.Sheets.Bindings.CellBindingSource({});
  5.   spread.getActiveSheet().setDataSource(source);
  6.   getBindingPathKeys();
  7. }

  8. function getBindingPathKeys() {
  9.   const sheet = spread.getActiveSheet();
  10.   sheet.suspendPaint();
  11.   const rowCount = sheet.getRowCount();
  12.   const columnCount = sheet.getColumnCount();
  13.   const tables = sheet.tables.all();
  14.   let bindingPathKey;
  15.   const bindingPathArray = [];

  16.   for (let i = 0; i < rowCount; i++) {
  17.     for (let j = 0; j < columnCount; j++) {
  18.        bindingPathKey = sheet.getBindingPath(i, j);
  19.        if (bindingPathKey) {
  20.          bindingPathArray.push({
  21.              bindingPath: bindingPathKey,
  22.              row:i,
  23.              col:j
  24.          });
  25.        }
  26.     }
  27.   }
  28.   
  29.   if(tables && tables.length > 0){
  30.     for(let i=0; i<tables.length; i++){
  31.       bindingPathArray.push({
  32.         bindingPath: tables[i].bindingPath(),
  33.         range: tables[i].range()
  34.       });
  35.     }
  36.   }

  37.   sheet.resumePaint();
  38.   console.log(bindingPathArray);
  39. }

  40. ngAfterViewInit();
复制代码


回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部