Google 电子表格获取单元格颜色

Google SpreadSheets get cell color

我在这上面浪费了一整天,还没解决。 我到底该如何创建一个 returns 指定单元格背景颜色的函数? 如何获取函数参数的范围,然后获取其背景颜色? 这是我试过的:

/**
 * 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;
 
}

您使用的函数设置为custom function

  • 这意味着它可以从电子表格中调用,并且 returns 一个值到调用它的单元格。

  • 要调用它,您需要在一个单元格中键入一个以 = 开头的单元格,并在作为函数参数传递的引号中使用范围符号。

调用示例:

=getColor("F2")

早上好附加提案 将 A1 放在引号中 "A1"

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

Ejemplos