我有一个 Apps 脚本函数,它返回单元格的背景颜色,但它要求参数用引号引起来,例如:
COLOR("A1")
。/**
* 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"。
您没有理由不能动态生成 A1 表示法字符串。
例如使用ADDRESS函数:
=COLOR(
ADDRESS(
[formula_01_returns_row_number],
[formula_02_returns_col_number],4))