为什么这个appcript的代码不起作用?

时间:2014-01-12 10:32:46

标签: javascript google-apps-script

如果row,我的代码可以移动col5=Published。如果col5=PublishedDeletedDenied function可行,我想添加更多内容。我试过像它一样使用

var valueToWatch = ("Published","Deleted","Denied"); 

但它不起作用。 stringDenied

只能使用Published Deleted
  var sheetNameToWatch = "Sheet1";
  var columnNumberToWatch = 5; // column A = 1, B = 2, etc.
  var valueToWatch = ("Published","Deleted","Denied");
  var sheetNameToMoveTheRowTo = "Sheet2";

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = SpreadsheetApp.getActiveSheet();
  var range = sheet.getActiveCell();

  if (sheet.getName() == sheetNameToWatch && range.getColumn() == columnNumberToWatch && range.getValue() == valueToWatch) {
    var targetSheet = ss.getSheetByName(sheetNameToMoveTheRowTo);
    var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    sheet.getRange(range.getRow(), 1, 1, sheet.getLastColumn()).moveTo(targetRange);
    sheet.deleteRow(range.getRow());
  }
}

1 个答案:

答案 0 :(得分:0)

尝试使用以下内容:

//var valueToWatch = ("Published","Deleted","Denied");
var valueToWatch = ['Published', 'Deleted', 'Denied'];
...
if (... && valueToWatch.indexOf(range.getValue()) > -1 && ...) {
   ...
}
...

调整代码中所需的所有内容。