簡體   English   中英

谷歌電子表格的日期戳

[英]Date stamp for google-spreadsheet

我需要一些幫助在此代碼中添加功能。 到目前為止,如果修改了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
        }
    }
}

您可以查看此代碼是否適合您?

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行的編輯內容,因為我認為您可能在其中有標題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM