Google Apps脚本-表格-包含INCLUDES的IF语句

时间:2018-12-13 13:31:03

标签: google-apps-script google-sheets

我正在尝试创建一个脚本,该脚本根据E列中的内容复制行。如果该列具有“ CORE”,“ WARRANTY”或包含“ DAMAGE”,则会对其进行复制。我已经在下面的代码中找到了“ CORE”和“ WARRANTY”部分,但是我不确定如何使用INCLUDES:

- invalid expression: Unexpected token { in

{lat: {{propertydata.latitude}} , lng: {{propertydata.longitude}} }

谢谢!

1 个答案:

答案 0 :(得分:0)

这段代码就是我最终的工作:

function onEdit(event) {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = event.source.getActiveSheet();
  var r = event.source.getActiveRange();

  if(s.getName() == "MAIN" && r.getColumn() == 5 && r.getValue() == "CORE"  || r.getValue() == "WARRANTY" || event.value.indexOf("DAMAGE") >= 0) {
    var row = r.getRow();
    var numColumns = s.getLastColumn();
    var targetSheet = ss.getSheetByName("ELITE");
    var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    s.getRange(row, 1, 1, numColumns).copyTo(target);
    }
}