gpt4 book ai didi

google-apps-script - 谷歌表格 : Prevent the unchecking of a checkbox after it has been checked

转载 作者:行者123 更新时间:2023-12-04 08:45:44 25 4
gpt4 key购买 nike

是否有条件语句或公式来防止在用户选中复选框后取消选中复选框?

最佳答案

解决方案:
您可以利用 Class Protection如果选中复选框,则保护单元格;值变为 TRUE .

function onEdit(e) {

const row = e.range.getRow();
const col = e.range.getColumn();
const as = e.source.getActiveSheet();

if(as.getName() == "Sheet1" && col == 2 && row > 1 && e.range.getValue()===true) {

const protection = as.getRange(row,col).protect();

// Ensure the current user is an editor before removing others. Otherwise, if the user's edit
// permission comes from a group, the script throws an exception upon removing the group.
const me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}

}
}
  • 随意修改"Sheet1"col == 2 ( 2 对应
    栏目 )。
  • 要启用此代码片段,复制和粘贴 它到脚本编辑器
    ( Tools => Script Editor ) 然后点击 保存 .

  • 例子:
    result

    关于google-apps-script - 谷歌表格 : Prevent the unchecking of a checkbox after it has been checked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64336535/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com