如何使用脚本在Google表格上编辑受保护的单元格范围

时间:2017-12-04 18:35:58

标签: javascript google-sheets-query

我创建了一个跟踪器,可以在编辑单元格时自动在下一个单元格中捕获时间。并且应该保护时间不被手动编辑(通过受保护的范围)。我有以下脚本,但不知道如何在用户不能编辑受保护范围的表格中实现它,但脚本应该如此。

function onEdit() {
    var s = SpreadsheetApp.getActiveSheet();
    if( s.getName() == "Sheet1" ) { //checks that we're on the correct sheet
        var r = s.getActiveCell();
        if( r.getColumn() == 3 ) { //checks the column
            var nextCell = r.offset(0, 1);
            //if( nextCell.getValue() !== '' ) //is empty?
            nextCell.setValue(new Date());
        }

        if( r.getColumn() == 5 ) { //checks the column
            var nextCell = r.offset(0, 1);
            //if( nextCell.getValue() !== '' ) //is empty?
            nextCell.setValue(new Date());
        }
    }
}

当最终用户在受保护范围之前编辑单元格时,我希望脚本在受保护的范围内运行

该脚本对我来说很好。但不适用于无法编辑受保护范围的用户。

0 个答案:

没有答案