删除双单元格保护谷歌页



我有一个脚本,在添加条目后保护单元格。删除表项后,将取消保护。不幸的是,如果有人在工作表单元格中重写,它会保护两次。当条目被删除时,它只删除一个保护。有没有办法让它取消所有的保护?

function findProtectionFromRange(range) {
let row = range.getRow();
let col = range.getColumn();
let protections = range.getSheet().getProtections(SpreadsheetApp.ProtectionType.RANGE);
return protections.find((protection) => {
let protectionRange = protection.getRange();
if (row === protectionRange.getRow() && col === protectionRange.getColumn()) {
return protection;
}
return null;
});
}
function onEdit(e) {
let range = e.range;
let protection = findProtectionFromRange(range);

if (e.value === undefined && protection) {
protection.remove();
return;

好的,您有一个脚本,一旦输入值就保护单元格,对吗?

解决办法很简单,那么,在保护之前检查电池是否已经受到保护。

最新更新