javascript - 设置背景 RGB 不接受函数参数

标签 javascript google-apps-script google-sheets

我想做什么

Make a function in google sheets that will allow me to select a cell and enter "=rgbcolour", select 3 separate cells containing numbers between 0 and 255 to act as rgb values so that the cell that I entered "=rgbcolour" into will turn the appropriate colour as per the 3 separate rgb inputs

我的研究

setBackGroundRGB not accepting string This person ran into the same error put his desired result, his methods used and the solution to his problem would not seem to apply

This setBackground() or setFontColor not working in GAS helped me try and figure out how to pass the cell, that the function would be entered into, into the setBackgroundRGB method. I ended up using var cell = sheet.getActiveCell();Although I may have been unsuccessful in this endeavour which may be contributing to my problems

I have been using https://developers.google.com/apps-script/guides/sheets/functions#using_a_custom_function as a guide

这是我的代码

function RGBCOLOUR(r,g,b)
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var cell = sheet.getActiveCell();
  
  return cell.setBackgroundRGB(r,g,b);
}

这是我的错误

Cannot find method setBackgroundRGB((class),(class),(class)). (line 7, file "RGB Colour Cell")

最佳答案

这是不可能的。根据文档,自定义函数只能返回值。不操纵格式。

https://developers.google.com/apps-script/guides/sheets/functions#return_values

如果我错了,请有人纠正我,以便我可以学到新的东西。

关于javascript - 设置背景 RGB 不接受函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34132202/

相关文章:

javascript - AngularJS - 使用 ng-repeat 的动态指令

google-apps-script - 如何将 Google 表格文件转换为 Excel 文件 (XLSX)

javascript - Google 脚本返回的不是数字

google-apps-script - folder.getFiles 不是触发器中的函数错误

google-apps-script - 找到一种方法来获取使用的库版本?

javascript - 如何在SCSS + Parcel.js中使用背景图像

javascript 将数组的元素映射到 HTML DIV 模板

javascript - 什么时候应该在 JavaScript 中使用 outerHTML?

google-apps-script - 在 Google Apps 脚本中存储 key 的最佳实践

javascript - 如何通过自定义函数/脚本通过正确的授权从 Google 表格中的文件名获取文件 URL