Compartir a través de


CustomFunctions.StreamingInvocation interface

Proporciona información sobre la invocación de una función personalizada de streaming. Una función personalizada de streaming puede proporcionar resultados que pueden cambiar con el tiempo.

Llame a setResult() una o más veces para proporcionar el resultado en lugar de devolver un resultado de la función.

Extends

Propiedades

setResult

Establezca el resultado de la función personalizada. Se puede llamar a más de una vez.

Detalles de las propiedades

setResult

Establezca el resultado de la función personalizada. Se puede llamar a más de una vez.

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

Valor de propiedad

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

Comentarios

[ Conjunto de API: CustomFunctionsRuntime 1.1 ]

Ejemplos

// 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);
  }
}