颜色自定义函数输入参数

问题描述 投票:0回答:1

我有一个 Apps 脚本函数,它返回单元格的背景颜色,但它要求参数用引号引起来,例如:

COLOR("A1")

我希望它接受引号之外的参数,以便我可以在 COLOR() 函数中执行函数。
这是我的函数的脚本:

/**
 * Returns the background color of a cell
 * 
 * @customfunction
 */

function COLOR(input) {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getActiveSheet();
  const bcolors = sh.getRange(input).getBackgrounds(); 
  return bcolors;
}

我也尝试在引号内传递它的函数,但这不起作用。我期望能够更改我的函数找到的颜色的单元格,但如果它在引号中,例如:COLOR("A1"),我无法将 A1 更改为其他内容,假设有类似 xlookup 函数的东西代替“ A1"。

google-sheets google-apps-script custom-function
1个回答
0
投票

您没有理由不能动态生成 A1 表示法字符串。

例如使用ADDRESS函数:

=COLOR(
   ADDRESS(
     [formula_01_returns_row_number], 
     [formula_02_returns_col_number],4)) 
© www.soinside.com 2019 - 2024. All rights reserved.