Share via


CustomFunctions.StreamingInvocation interface

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

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

Extends

プロパティ

setResult

カスタム関数の結果を設定します。 複数回呼び出される場合があります。

プロパティの詳細

setResult

カスタム関数の結果を設定します。 複数回呼び出される場合があります。

setResult: (value: ResultType | Error) => void;

プロパティ値

(value: ResultType | CustomFunctions.Error) => void

注釈

[ API セット: CustomFunctionsRuntime 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/16-custom-functions/streaming-function.yaml

/** @CustomFunction 
 * @description Increments the cell with a given amount at a specified interval in milliseconds.
 * @param {number} amount - The amount to add to the cell value on each increment.
 * @param {number} interval - The time in milliseconds to wait before the next increment on the cell.
 * @param {CustomFunctions.StreamingInvocation<number>} invocation - Parameter to send results to Excel
 *     or respond to the user canceling the function.
 * @returns An incrementing value.
 */
function increment(amount: number, interval: number, invocation: CustomFunctions.StreamingInvocation<number>): void {
  let result = 0;
  const timer = setInterval(() => {
    result += amount;
    invocation.setResult(result);
  }, interval);

  invocation.onCanceled = () => {
    clearInterval(timer);
  }
}