Share via

How do I make a streaming Excel Custom Function which returns FormattedNumberCellValue or EntityCellValue?

Jason Murad 5 Reputation points
2023-10-02T19:56:41.4633333+00:00

I have a streaming API. I was able to successfully wire it up as CustomFunctions.StreamingInvocation<string>.

But I would like to return as a Excel.EntityPropertyType so I can use numberFormat with Excel.CellValueType.formattedNumber. This is primarily so I can format it by default for consumers but also because I didn't seem to able to have Excel use "Format Cells" or decimal precision control on the string return type.

When I first use the formula, the cell renders fine. But it breaks upon update. It displays #VALUE! with error A value used in the formula is of the wrong data type.

I tried modifying my functions.json with allowCustomDataForDataTypeAny but that didn't make a difference.

What I'd really like to do is have a streaming Excel.EntityCellValue so I could have multiple data properties like bid/mid/offer. I did try that first and it went the same way... looked great upon first render and then broke on updates; so I'd be happy enough if I could do one customfunction per property.

Here is a simplified version of the code:

/**
 * @customfunction
 */
export function test(invocation: CustomFunctions.StreamingInvocation<any>): void {
  let dollars = 100;

  const timer = setInterval(() => {
    invocation.setResult({
      basicValue: dollars++,
      numberFormat: "$0.000",
      type: Excel.CellValueType.formattedNumber,
    });
  }, 3000);

  invocation.onCanceled = () => {
    clearInterval(timer);
  };
}
Microsoft 365 and Office | Development | Office JavaScript API
Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.