arrays - 识别/合并 [] 范围数组中的相邻单元格,以限制 [] 范围数组中的#ranges
问题描述
这是一个谷歌工作表脚本
- 保护纸张,然后
- 在工作表中创建一系列所有“公式”单元格,然后
- 创建所有不是公式的工作表单元格的 [](也就是不在公式范围内),然后
- 取消保护 [] 中的所有单元格
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。
有没有办法做到这一点?
我为什么要这样做?
这是一张非常大的表格,里面有很多公式和空白区域
- 如果可能的话,限制脚本的操作,因为它需要很长时间才能运行。
- 拥有单独的单元格范围会减慢受保护页面功能的打开/关闭速度
- 因为受保护的工作表是一个将被复制多次的模板。我编写了另一个函数来复制具有完整保护的工作表,由于上述原因,它显然运行得很慢。
- 必须保护工作表是因为还有其他用户将与工作表进行交互。他们会将信息输入到一些非公式单元格中(这当然是需要保护工作表的敏感部分的原因)
解决方案
推荐阅读
- jquery - 更改未来实例的 CSS
- javascript - 带有 package.json 链接的 CLI bin 可执行节点
- c - 为什么我不能用 C 语言重写 .txt 文件?
- angular - dx-load-panel,DevExtreme 角度组件的“容器”属性可以分配什么值?
- r - R Studio 未安装
- php - 如何扩展学说实体以使用 API 平台
- javascript - 我的自动完成字段不适用于引导程序
- wpf - WPF 依赖属性 - 从 XAML 设置
- boolean - 'loginpage.Type' 不能转换为 '(Binding
) -> 登录页面' - javascript - 分解 JS 函数