title: Set colors at once on a range of cells
body: <p>Setting colors of cells 1 by 1 is extremely slow. It is advised to do that by assigning an array to the range. I read about that and there is often refered to the following sample. However I can't get this to work so it doesn't help me.</p>
  
  <pre><code>var cell = sheet.getRange('a1');
  var colors = new Array(100);
  for (var y = 0; y &lt; 100; y++) {
    xcoord = xmin;
    colors[y] = new Array(100);
    for (var x = 0; x &lt; 100; x++) {
      colors[y][x] = getColorFromCoordinates(xcoord, ycoord);
      xcoord += xincrement;
    }
    ycoord -= yincrement;
  }
  sheet.getRange(1, 1, 100, 100).setBackgroundColors(colors);
  </code></pre>
  
  <p>My piece of code is the following and ends with the message (error): Cannot convert array to object[[]], pointing at the last line.</p>
  
  <pre><code>function TabelMarkeren() {
    var selection = SpreadsheetApp.getActiveSpreadsheet().getRangeByName("Proef") // 6 by 3;
    var colors = [];
  
    for (var row = 1; row &lt;= selection.getNumRows(); ++row) {
      var cell = selection.getCell(row, 1);
      if (cell.isBlank()) {
    colors[row, 1] = "#86d8b6";
  }// if
  else {
    colors[row, 1] = "c4c4a4";
    }// else
    colors[row, 2] = "blue";
    colors[row, 3] = "green";
  }// for
  SpreadsheetApp.getActiveSpreadsheet().
  getRangeByName("Proef").setBackgrounds(colors);
  }
  </code></pre>
  
  <p>When I use a Browser.msgBox . .  to show me some values from the array. It is ok. But clearly setBackgroundColors wants an object and not an array.</p>