如何将范围传递到Google Spreadsheets中的自定义功能? [英] How to pass a range into a custom function in Google Spreadsheets?

查看:140
本文介绍了如何将范围传递到Google Spreadsheets中的自定义功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我知道谷歌可以让您通过工具比较表格,但是我需要一个更自定义的比较,因此这个功能。



我想创建一个占用范围的函数,如:

  function myFunction(range){
var firstColumn = range.getColumn();
//循环超出范围
}

问题是,当我尝试这样做,参数似乎只是将值传递给函数。因此,我不能使用任何Range方法,如getColumn()。当我尝试这样做时,会出现以下错误:

 错误:TypeError:在对象1,2中找不到函数getColumn ,3。 

如何将实际范围发送给我的一个自定义函数? p>

注意 - 我的情况下的范围是整个表格(两者都需要比较)。



谢谢!

解决方案

Google脚本将范围视为数组。所以,当您使用数组时,您可以更好地使用输入的范围。以下是如何循环访问数组的好技巧:
https://stackoverflow.com/a/14991272/5372400


I am trying to compare two google sheets (for duplicate values) over a predefined range..

I am aware that google lets you compare sheets via tools, but i need a more customized comparison hence the function.

I want to create a function which takes in a range... something like:

    function myFunction(range) {
    var firstColumn = range.getColumn();
    // loop over the range
    }

The problem is that when I try doing this, the parameter seems like it is only passing the values to the function. Thus, I cannot use any of the Range methods such as getColumn(). When I attempt to do so, it gives the following error:

    error: TypeError: Cannot find function getColumn in object 1,2,3.

How can I send an actual range rather than just the values to one of my custom functions?

Note- Range in my case is the entire sheet (both of them that need to be compared).

Thanks!

解决方案

Google Script treats ranges as Arrays. So, you could better work with entered range as you work with an array. Here's good technique how to loop through an array: https://stackoverflow.com/a/14991272/5372400

这篇关于如何将范围传递到Google Spreadsheets中的自定义功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆