运行循环时,Google Apps脚本会挂起

时间:2017-10-03 12:18:42

标签: javascript google-apps-script

我正在使用此代码,但我无法在记录器中看到任何内容。我只能看到一条消息"准备执行"

function testfunc() {
  var s = SpreadsheetApp.getActiveSpreadsheet()
  var sheet = s.getSheetByName("data")
  var lastRow = sheet.getLastRow() - 1
  var data = sheet.getRange(2,2,lastRow,5).getValues()
  var fms = s.getSheetByName("FMS")
  for (var i = 0;i < data.length; ++i){
   var row = data[i]
   var a = row[0]
   var b = row[1]
   var c = row[2]
   var d = row[3]
   var e = row[4]
   Logger.log(i)
   if (i = 1) {
     Logger.log(i)
   }
  }
}

我哪里出错了?

编辑:正如@FedericoklezCulloca指出的那样,我在if语句中错过了相同的签名。代码应该是:

function testfunc() {
  var s = SpreadsheetApp.getActiveSpreadsheet()
  var sheet = s.getSheetByName("data")
  var lastRow = sheet.getLastRow() - 1
  var data = sheet.getRange(2,2,lastRow,5).getValues()
  var fms = s.getSheetByName("FMS")
  for (var i = 0;i < data.length; ++i){
   var row = data[i]
   var a = row[0]
   var b = row[1]
   var c = row[2]
   var d = row[3]
   var e = row[4]
   Logger.log(i)
   if (i == 1) {
     Logger.log(i)
   }
  }
}

0 个答案:

没有答案