简体   繁体   中英

Google Apps Script - Very Basic Loop Problem Using isChecked()

Column J has checkboxes. Trying to create a loop statement to check if the row has an enabled checkbox (TRUE). Rows 1-3 are checked (TRUE). When I run this statement, logger is showing all rows as null when my expected result is for logger to show rows 1-3 as enabled (TRUE) and 4-500 as null.

function checkRangeTest(){
  for(var row = 1; row <=500; row++){
    var range = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("J2:J500");

    Logger.log("Row "+ row + " is checked? " + range.isChecked());
  };
};

Testing the Value of Each Checkbox in column J of the Active Sheet

function checkRangeTest(){
  var html="";
  var ss=SpreadsheetApp.getActive();
  var shsr=2;//start row
  var sh=ss.getActiveSheet();
  var rg=sh.getRange(shsr,10,sh.getLastRow()-shsr+1,1);
  var values=rg.getValues();
  values.forEach(function(r,i){
    html+=Utilities.formatString('<br />Row: %s Value: %s',i+shsr,r[0]);
  });
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html), "Checkboxes");//creates a dialog displaying all of the results
}

Checkboxes:

在此处输入图像描述

var values = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("J2:J500").getValues();
for(var row = 2; row <=500; row++){
  Logger.log("Row "+ row + " is checked? " + (values[row-2] === true));
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM