custom-functions-runtime package

クラス

CustomFunctions.Error

このクラスを使用して、エラーを処理し、カスタム エラー メッセージを書き込みます。

インターフェイス

CustomFunctions.CancelableInvocation

キャンセル可能なカスタム関数の呼び出しに関する情報を提供します。 キャンセル可能なカスタム関数は、onCanceled イベントのハンドラーを提供できます。

関数がキャンセル可能であることを示すには、メタデータ JSON ファイルで関数オプションで以下を指定する必要があります。 { "cancelable": true }

メタデータ JSON ファイルが JSDoc コメントから生成されている場合は、タグ @cancelableを含めます。

CustomFunctions.Invocation

カスタム関数の呼び出しに関する情報を提供します。

CustomFunctions.StreamingInvocation

ストリーミング カスタム関数の呼び出しに関する情報を提供します。 ストリーミング カスタム関数を使用すると、時間の経過と共に変化する可能性のある結果を提供できます。

関数から結果を返す代わりに、結果を提供するには、 setResult() を 1 回以上呼び出します。

列挙型

CustomFunctions.ErrorCode

カスタム関数のエラー コード。 関数を呼び出したセルにエラー コードが表示されます。

これらのエラー コードに加えて、カスタム エラー メッセージが表示されます。 カスタム メッセージはエラー インジケーター メニューに表示されます。このメニューには、エラーが表示されている各セルのエラー フラグにカーソルを合わせることでアクセスします。

関数

CustomFunctions.associate(id, functionObject)

JavaScript 関数をメタデータ JSON ファイルの "id" プロパティによって指定された名前に関連付けます。

CustomFunctions.associate(mappings)

JavaScript 関数を、メタデータ JSON ファイルの "id" プロパティによって指定された名前に関連付けます。

関数の詳細

CustomFunctions.associate(id, functionObject)

JavaScript 関数をメタデータ JSON ファイルの "id" プロパティによって指定された名前に関連付けます。

export function associate(id: string, functionObject: Function): void;

パラメーター

id

string

functionObject

Function

返品

void

/**
* Adds two numbers together.
* @customfunction
* @param {number} first First number.
* @param {number} second Second number.
* @returns {number} The sum of the two numbers.
*/
// Define your custom function.
function add(first, second) {
  return first + second;
}

// Associate the "add" function with its ID from the JSON metadata. In this sample, the JSON metadata ID is "ADD".
CustomFunctions.associate("ADD", add);

CustomFunctions.associate(mappings)

JavaScript 関数を、メタデータ JSON ファイルの "id" プロパティによって指定された名前に関連付けます。

export function associate(mappings: { [key: string]: Function }): void;

パラメーター

mappings

{ [key: string]: Function }

返品

void

/**
* Calculates the area of a rectangle.
* @customfunction
* @param {number} width The width of the rectangle.
* @param {number} height The height of the rectangle.
* @returns {number} The area of the rectangle.
*/
function calculateArea(width, height) {
  return width * height;
}

/**
* Calculates the perimeter of a rectangle.
* @customfunction
* @param {number} width The width of the rectangle.
* @param {number} height The height of the rectangle.
* @returns {number} The perimeter of the rectangle.
*/
function calculatePerimeter(width, height) {
  return 2 * (width + height);
}

// Associate multiple functions at once using an object that maps JSON metadata IDs to function names.
// In this sample, the "calculateArea" and "calculatePerimeter" functions have the JSON metadata IDs "CALCULATEAREA" and "CALCULATEPERIMETER".
CustomFunctions.associate({
  "CALCULATEAREA": calculateArea,
  "CALCULATEPERIMETER": calculatePerimeter
});