Created
November 15, 2022 02:55
-
-
Save jiju-MS/dc82c4daa97ade509bb234c68ebf2bc8 to your computer and use it in GitHub Desktop.
A streaming function that continuously increments the cell value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Streaming function | |
description: A streaming function that continuously increments the cell value. | |
host: EXCEL | |
api_set: {} | |
script: | |
content: > | |
/** @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 {any} interval - The time in milliseconds to wait before the next increment on the cell. | |
* @param {CustomFunctions.StreamingInvocation<any[][]>} invocation - Parameter to send results to Excel | |
* or respond to the user canceling the function. | |
* @returns An incrementing value. | |
*/ | |
function increment(amount: number, interval: any, invocation: | |
CustomFunctions.StreamingInvocation<any[][]>): void { | |
var Entity1 = { | |
type: "Entity", | |
basicType: "Error", | |
basicValue: "#VALUE!", | |
text: "Entity 1", | |
properties: { | |
TestDouble: { type: "Double", basicType: "Double", basicValue: 1 }, | |
TestString: { type: "String", basicType: "String", basicValue: "Test" } | |
} | |
}; | |
var Entity2 = { | |
type: "Entity", | |
basicType: "Error", | |
basicValue: "#VALUE!", | |
text: "Entity 2", | |
properties: { | |
TestDouble: { type: "Double", basicType: "Double", basicValue: 2 }, | |
TestString: { type: "String", basicType: "String", basicValue: "Test" } | |
} | |
}; | |
let result = [[Entity1], [Entity2]]; | |
const timer = setInterval(() => { | |
Entity1.properties.TestDouble.basicValue += amount; | |
Entity2.properties.TestDouble.basicValue += amount | |
invocation.setResult(result); | |
}, interval); | |
invocation.onCanceled = () => { | |
clearInterval(timer); | |
}; | |
} | |
language: typescript | |
libraries: | | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
@types/office-js | |
core-js@2.4.1/client/core.min.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment