如何创建将数据返回到多个单元格的自定义函数 [英] How to create a custom function that returns data to multiple cells
问题描述
我需要在Google Apps脚本中创建一个自定义函数,该函数将允许我输入某些单元格的位置,然后该函数将输出到新的单元格中。这是我尝试过的事情:
I need to create a custom function in Google Apps Script that will allow me to input the location of certain cells and then the function would output into new cells. This is what I tried sofar:
function SetRange(RowNum) {
var app = SpreadsheetApp;
var ss = app.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
sheet.getActiveCell(),setValue(45)
sheet.getRange(RowNum,24),setValue(51);
}
我收到未定义SetValue的错误。我正在学习时正在构建此程序,因此有些事实是资深程序员会知道我不知道。再次感谢您的所有帮助
I get the error that "SetValue is not defined. I am building this program as I learn so there are some facts that veteran programmers would know that I do not. Thanks again for all your help
推荐答案
自定义函数可以返回一个值数组,但不能使用setValue()或setValues()。
Custom functions could return an array of values but can't use setValue() or setValues().
示例
function demo(){
var output = [
[1,2],
[3,4]
]
return output;
}
如果加上 = demo()
到A1,结果将是:
If we add =demo()
to A1, the result will be:
| A | B |
--+-----+-----+
1| 1| 2|
2| 3| 4|
这篇关于如何创建将数据返回到多个单元格的自定义函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!