Performance 如果单元格通过appscript修改了col1上的数据?
我要 如果B1已编辑/不为空,则在A1上添加时间戳。这是我的剧本-Performance 如果单元格通过appscript修改了col1上的数据?,performance,google-apps-script,Performance,Google Apps Script,我要 如果B1已编辑/不为空,则在A1上添加时间戳。这是我的剧本- 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() == 2 ) { //checks the c
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() == 2 ) { //checks the column
var nextCell = s.getRange(r, 1);
if( nextCell.getValue() !== '' ) //is not empty
nextCell.setValue(new Date());
}
}
}
问题是,getRange(r,1)
应该是getRange(r,-1)
作为colB=0,colC=1 colA=-1
但是推杆-1不起作用。如何解决这个问题???试试这个
if(r.getColumn() == 2){
var prevCellValue = r.offset(0,-1).getValue;
if(prevCellValue() !== ''){
r.offset(0,-1).setValue(new Date());
}
}