Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 如果单元格通过appscript修改了col1上的数据?_Performance_Google Apps Script - Fatal编程技术网

Performance 如果单元格通过appscript修改了col1上的数据?

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

我要

如果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 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());
    }
}