Guest User

Untitled

a guest
Apr 18th, 2012
17,074
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getBackgroundColor(rangeSpecification) {
  2.   var sheet = SpreadsheetApp.getActiveSpreadsheet();
  3.   return sheet.getRange(rangeSpecification).getBackgroundColor();
  4.  
  5. }
  6.  
  7. function sumWhereBackgroundColorIs(color, rangeSpecification) {
  8.  
  9.   var sheet = SpreadsheetApp.getActiveSpreadsheet();
  10.   var range = sheet.getRange(rangeSpecification);
  11.  
  12.   var x = 0;
  13.  
  14.   for (var i = 1; i <= range.getNumRows(); i++) {
  15.     for (var j = 1; j <= range.getNumColumns(); j++) {
  16.      
  17.       var cell = range.getCell(i, j);
  18.      
  19.       if(cell.getBackgroundColor() == color)
  20.         x += parseFloat(cell.getValue());
  21.     }
  22.   }
  23.  
  24.   return x;
  25. }
  26.  
  27. function countCellsWithBackgroundColor(color, rangeSpecification) {
  28.  
  29.   var sheet = SpreadsheetApp.getActiveSpreadsheet();
  30.   var range = sheet.getRange(rangeSpecification);
  31.  
  32.   var x = 0;
  33.  
  34.   for (var i = 1; i <= range.getNumRows(); i++) {
  35.     for (var j = 1; j <= range.getNumColumns(); j++) {
  36.      
  37.       var cell = range.getCell(i, j);
  38.      
  39.       if(cell.getBackgroundColor() == color)
  40.         x++;
  41.     }
  42.   }
  43.  
  44.   return x;
  45. }
RAW Paste Data