Search code examples
google-sheets-api

Google SpreadSheets get cell color


I wasted a whole day on this and still haven't solved it. How the hell do I create a function that returns the background color of a specified cell? How to get the range of the function's argument, and then its background color? This is what I tried:

/**
 * Returns the Hexadecimal value of a cell's background color.
 * @param {cel} input The cell to get color.
 * @customfunction
 */
function getColor(cel) {
  var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(cel);
  var background = ss.getBackground();
  return background;
 
}


Solution

  • Good morning attached proposal put A1 in quotation marks "A1"

    function myBackgroundRanges(myRange,myTigger) {  
      return SpreadsheetApp.getActiveSpreadsheet()
              .getActiveSheet()
                .getRange(myRange)
                  .getBackgrounds();}
    

    Ejemplos