简体   繁体   English

传递动态范围:Google脚本

[英]Passing Dynamic Range:Google Script

I'm trying to write a custom function that will count and return the number of cells that contain information on a singular column. 我正在尝试编写一个自定义函数,该函数将计算并返回包含单数列信息的单元格数。 I'm using a range of A(x):Z(x) and I can't seem to dynamically pass these so I can get a user defined range everytime. 我正在使用A(x):Z(x)的范围,但似乎无法动态传递这些范围,因此每次都能获得用户定义的范围。

Edit: Current Error I'm receiving right now says: Missing ) after argument list. 编辑:当前错误我现在收到的消息是:参数列表后缺少)。 (line 10, file "Number Of Updates") (第10行,文件“更新数量”)

So far I have this.... 到目前为止,我有这个。

function updateNum(row1,col1,row2,col2)
{
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var s = ss.getSheetByName("report status");
 var r = s.getActiveRange(row1+col1:row2+col2); <---Line with error
 return (range.length-2)/2
}

any suggestions on how I could make this pass the range? 关于如何使它通过范围的任何建议?

thanks, Alexander 谢谢,亚历山大

change the line for: 将行更改为:

var r= s.getRange(row1, col1, row2-row1+1, col2-col1+1); 

but that won't solve your problems has the line just behind is a non sense. 但这不能解决您的问题,因为后面的线是没有意义的。 "range" is not declared. 未声明“范围”。 I don't see where you want to go exactly. 我看不到您要去的确切位置。 please write some pseudocode. 请写一些伪代码。

If what you want is to count the number of cells that got informations in it, just use the spreadsheet native function 如果要计数包含信息的单元格的数量,请使用电子表格本机函数

counta()

Its not possible with custom functions because they are deterministic. 使用自定义函数是不可能的,因为它们是确定性的。 That is, they will return the same result given the same input. 也就是说,给定相同的输入,它们将返回相同的结果。 In your case even if you fix the bugs you are still not passing the actual input just its range limits. 就您而言,即使您修复了这些错误,您仍然没有通过实际输入,只是其范围限制。 Thus if the data inside the range changes you still pass the same input limits thus will return the previous cached result. 因此,如果范围内的数据发生更改,您仍将通过相同的输入限制,因此将返回先前的缓存结果。 There are ways arround that like passing an extra parameter that always changes like 'now()'but that has performance problems as it will recalculate constantly. 有一些方法可以传递一个额外的参数,该参数总是像'now()'那样变化,但是由于会不断地重新计算而导致性能问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM