首页 > 解决方案 > 识别/合并 [] 范围数组中的相邻单元格,以限制 [] 范围数组中的#ranges

问题描述

这是一个谷歌工作表脚本

  1. 保护纸张,然后
  2. 在工作表中创建一系列所有“公式”单元格,然后
  3. 创建所有不是公式的工作表单元格的 [](也就是不在公式范围内),然后
  4. 取消保护 [] 中的所有单元格
function protectFormulas() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getActiveSheet();
  let up = [];
  let protection=sh.protect();
  const range = sh.getDataRange();
  const formulas = range.getFormulas();
  formulas.forEach((r, i) => {
    r.forEach((c, j) => {
      if (c == '') {//if not a formula then add range to up
         up.push(sh.getRange(i+1,j+1));
      }
    });
  });
  protection.setUnprotectedRanges(up);//unprotect ranges in up
}

但是,由于“up”只有“单个单元格”范围,我想在“up”中将所有相邻单元格合并在一起,以限制其中的#ranges。

有没有办法做到这一点?

我为什么要这样做?

这是一张非常大的表格,里面有很多公式和空白区域

标签: arraysgoogle-apps-scriptgoogle-sheets

解决方案


推荐阅读