且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

防止删除可被许多用户编辑的工作表中的复选框

更新时间:2023-12-02 07:59:04

这里有一个示例,说明如何使用 onOpen触发器

Here you have an example on how to achive it using onOpen triggers

function onOpen(e) 
{
  var range = SpreadsheetApp.getActive().getSheets()[0].getRange(1,4,5);
  var values = range.getValues();

  for ( var val in values ) {
    if( values[val] != true && values[val] != false ) {
      values[val]= false;
    }
  }

  range.insertCheckboxes(values);
}

您必须指定复选框的位置,在此处提供的代码示例中是5个,从第1行到第5行,它们放在第4列,即D。

You have to specify where are the checkboxes placed, in the code example provided there are 5 of them, starting from row 1 to row 5, and they are placed on the 4th column, so called D.

这是在getRange(1, 4,5)函数:

This is specified on the getRange(1,4,5) function:

getRange(InitialRow,初始列,行数)

有关使用getRange()的更多文档,请使用以下引用

for more documentation around the use of getRange() use the following reference.

此onOpen函数将在每次打开电子表格时执行,如果在指定的字段上没有 false true 语句,这意味着我们以某种方式丢失了复选框,因此将再次介绍它们。

This onOpen function will be executed every time that the spreadsheet is opened, and if on the specified fields there aren't false or true statements, it means that we lost the checkbox somehow, so it will introduce them again.