我有一个google脚本,如果编辑了其他列中的数据,它会自动在特定列中输入今天的日期。它效果很好,但我今天发现了#2; 2月1日和#34;正在进入" 2月32日"。以下是我的代码:
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
var r = s.getActiveCell();
var sheetName = SpreadsheetApp.getActiveSheet().getSheetName();
//range to edit
var editRange = { // K:AB
left : 11,
right : 28
};
// Exit if we're out of range
if (r.getColumn() < editRange.left || r.getColumn() > editRange.right) return;
//Perform if on sheets if it ends in "15" "16" or "Old"/"old"
if(sheetName.indexOf("15")>-1 || sheetName.indexOf("16")>-1 || sheetName.indexOf("Old")>-1 || sheetName.indexOf("old")>-1){
if( r.getColumn() != 2) { //checks the column
var row = r.getRow();
var time = new Date();
time = Utilities.formatDate(time, "MST", "DDMMMYYYY");
SpreadsheetApp.getActiveSheet().getRange('C' + row.toString()).setValue(time);
}
};
};