0

我需要一些帮助来为此代码添加功能。到目前为止,如果 C 2 被修改,它会在 D 2 上添加一个日期戳,但我希望在我清除 C 2 上的内容时清除日期戳,但我无法成功实现这一点。

任何帮助将不胜感激。

谢谢。

function onEdit() {
    var s = SpreadsheetApp.getActiveSheet();
    if( s.getName() == "Add Payroll" ) {
        //checks that we're on the correct sheet
        var r = s.getActiveCell();
        if( r.getColumn() == 3 ) {
            //use getRow for row and getColumn
            for column
                var nextCell = r.offset(0, 1);
                //offset (row,column)
                if( nextCell.getValue() === "" )
                    //is empty?
                    nextCell.setValue(new Date());
                    //will only put date, format "123/Date and time" if time needed
        }
    }
}
4

1 回答 1

0

你能看看这段代码是否适合你吗?

function onEdit(e) {
if (e.source.getActiveSheet()
    .getName() !== "Add Payroll" || e.range.columnStart !== 3 || e.range.rowStart === 1) return;
e.range.offset(0, 1)
    .setValue(e.value ? new Date() : null)

}

注意:我还删除了第 1 行的编辑,因为我认为您可能在其中有标题..

于 2014-11-20T22:33:46.603 回答