How to create a custom function that returns data to multiple cells

女生的网名这么多〃 提交于 2019-12-11 16:11:22

问题


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);

  }

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


回答1:


Custom functions could return an array of values but can't use setValue() or setValues().

Example

function demo(){
  var output = [
    [1,2],
    [3,4]
  ]
  return output;
}

If we add =demo() to A1, the result will be:

  |  A  |  B  |
--+-----+-----+
 1|    1|    2|
 2|    3|    4|


来源:https://stackoverflow.com/questions/48464414/how-to-create-a-custom-function-that-returns-data-to-multiple-cells

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!