2

I'm trying to use the "Shared Runtime" to work with my Excel JS Add-In, but it's not working. Below are the docs that I have been reviewing. Below are screenshots of my project. It looks like I'm able to set an initial state but my custom function is not updating window.sharedState. I also tried using the Excel context object but that is not working either.

Documentation Links

  1. https://learn.microsoft.com/en-us/office/dev/add-ins/tutorials/share-data-and-events-between-custom-functions-and-the-task-pane-tutorial
  2. https://learn.microsoft.com/en-us/office/dev/add-ins/excel/configure-your-add-in-to-use-a-shared-runtime

Project Screenshots

My Excel Add-In Project (screenshot #1)

My Excel Add-In manifest.xml file (screenshot #2)

Rick Kirkham
  • 9,038
  • 1
  • 14
  • 32

1 Answers1

2

Thanks for sharing the key parts of your project! Your screenshots are very helpful!

The fact that your custom function can read the shared state is a good sign.

The reason why your custom function is not changing the shared state may be because you are not providing a valid JSON. I see several problems with the values you are trying to set:

  1. The { ... } must be a literal, i.e. you cannot use variables inside. Thus, things like { oldVal: originalVal } are not valid. If you want to use variables, you'll have to programmatically assign those values, e.g.
window.sharedState.test = {};
window.sharedState.test.oldVal = originalVal;
  1. The literal { first, second } is not valid - it doesn't adhere to the property: value pattern.
  2. While JavaScript and TypeScript may allow unquoted property names, it is good to develop the habit of quoting them like { "something": 42 }.
  • Thanks for the feedback. I tried this out and no change. I think another red flag that something is off is that I also cannot access the Excel context object like the documentation shows. This feature plus the window.sharedState are part of the shared statement api based on the docs. – Tony Hunter Jun 13 '20 at 01:13
  • Or, if you want to start with a sample that doesn't require any building or deployment, put this manifest on a file share, and side-load it - https://github.com/OfficeDev/custom-functions/blob/master/addins/upgrade/upgrade_shared.xml. All of the code is in the same GitHub folder. – Zlatko Michailov - MSFT Jun 13 '20 at 03:37
  • This sample is great. I checked it against my manifest file and everything looks good. Here is my manifest.xml file. manifest.xml file link: https://gist.github.com/thunter05/60dbb0cdca986aaeccd0f2e5e7afe17f – Tony Hunter Jun 13 '20 at 18:28
  • Your manifest does look good. It was even looking good yesterday. If it wasn't good, you'd see an installation error. I suspect your JavaScript is still bad. BTW, what do you see - an error or just no effect? Are you able to create a function that returns a constant number without any side effect, and can you use it in a formula? – Zlatko Michailov - MSFT Jun 13 '20 at 23:08