Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streaming asynchronous custom function failed to calculate time #4482

Closed
Edward-Zhou opened this issue May 21, 2024 · 1 comment
Closed

streaming asynchronous custom function failed to calculate time #4482

Edward-Zhou opened this issue May 21, 2024 · 1 comment
Assignees
Labels
Area: custom functions Issue related to the Excel custom functions feature Needs: author feedback Waiting for author (creator) of Issue to provide more info Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP

Comments

@Edward-Zhou
Copy link

I am developing with Excel AddIn cusotm function, and I made a test with Create a streaming asynchronous custom function

If I test with return value is number, the calculation is correct, but if the return value is date, the formula in Excel cell will return #Value

Here is my test code

/** @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, invocation: CustomFunctions.StreamingInvocation<number>): void {
  let result = 0;
  const timer = setInterval(() => {
    result += amount;
    invocation.setResult(result);
  }, 1000);

  invocation.onCanceled = () => {
    clearInterval(timer);
  };
}
/**
 * Returns the current time
 * @returns {string} String with the current time formatted for the current locale.
 */
function currentTime() {
  return new Date();
}

/**
 * Displays the current time once a second
 * @customfunction
 * @param {CustomFunctions.StreamingInvocation<string>} invocation Custom function invocation
 */
function clock(invocation) {
  const timer = setInterval(() => {
    const time = currentTime();
    invocation.setResult(time);
  }, 1000);

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

And there is my formula in Excel cell

B11: =SCRIPTLAB.STREAMINGFUNCTION.INCREMENT(1)
B12:=B11+10 // This will return dynamic value by B11 + 10
B13:=SCRIPTLAB.STREAMINGFUNCTION.CLOCK()
B14:=B13+10 //return "#Value"
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP label May 21, 2024
@shanshanzheng-dev shanshanzheng-dev added the Area: custom functions Issue related to the Excel custom functions feature label May 22, 2024
@XuanZhouMSFT
Copy link

Thanks for waiting. The #Value should be a by-design behavior. The streaming custom funtion "clock" you are using returns a string type. With the string type, the operation "+" could not work in Excel. So it will show the #Value.

@XuanZhouMSFT XuanZhouMSFT added the Needs: author feedback Waiting for author (creator) of Issue to provide more info label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: custom functions Issue related to the Excel custom functions feature Needs: author feedback Waiting for author (creator) of Issue to provide more info Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP
Projects
None yet
Development

No branches or pull requests

3 participants