1

パラメータとしての機能を渡す:Googleシートスクリプト:私はGoogleシートでスクリプトを作った

/** 
* @param {array} input A row or a column. 
* @param {function} condition A function returning bool. 
* @return The last value in the input satisfying the condition. 
* @customfunction 
*/ 
function GetLastGoodValIn1DArray(input, condition) { 
    // realization ... 
} 

私は次の引数を指定してこの関数を呼び出すしようとしています:

=GetLastGoodValIn1DArray(D11:H11;ISNUMBER) 

を次のエラーが表示されます。

Error

TypeError: #NAME? is not a function, but a string. (line 26).

明らかに 'ISNUMBER'は文字列として解釈されます。しかし、それを関数としてどのように渡すか?

+0

は、式が正しく書き込まれていません。 '= GetLastGoodValIn1DArray(D11:H11; ISNUMBER(something))'を試してください。ここで何かが値またはセル参照である可能性があります。 –

答えて

2

このold google docs forumとこのStack Overflow questionに従ってスクリプトから内部のGoogleシート機能にアクセスすることはできません。

Googleの内部機能でも、機能をパラメータとして使用できないことに注意してください。たとえば、内部関数SUBTOTALは、関数を直接呼び出すのではなく、目的の関数に対応する数値コードを取ります。

私が考えることができる最高ののは、Excelのような独自のWorksheetFunctionオブジェクトをビルドすることです。これは、文字列を受け取り、あなたが書いた関数を返すオブジェクトマップです。例えば:

var worksheetFunction = { 
    isnumber: function (x) { 
    return !isNaN(x); 
    } 
}; 

Another Note: ISNUMBER isn't passed as a string to your custom function. Google sheets first calculates it as an error and then passes the string #NAME? to your custom function. You can see this by using the formula =type(ISNUMBER) , which returns 16 (the code for an error) also in your custom function condition === "#NAME?" will evaluate to true.

関連する問題