3

I've deployed the Excel-Custom-Functions sample successfully and can use the new JS functions.

After changing the code/definition in customfunctions.js, I've restarted my web server, started Excel, inserted the custom functions from the Office Add-ins page again but still get the original functions.

If I start Excel without inserting the sample again, the functions are still known!?

How can I force Excel to remove such an add-in and reload it from scratch?

Example: The sample contains several custom functions and their corresponding registration:

Excel.Script.CustomFunctions["CONTOSO"]["ADD42"] = {
...
Excel.Script.CustomFunctions["CONTOSO"]["GETTEMPERATURE"] = {
...

Rename a function, and remove another function completely:

Excel.Script.CustomFunctions["CONTOSO"]["ADD42RENAMED"] = {
...
/* Excel.Script.CustomFunctions["CONTOSO"]["GETTEMPERATURE"] = {
...

Excel will still show the old metadata afterwards.

Michael Saunders
  • 2,662
  • 1
  • 12
  • 21
Kai
  • 67
  • 5

1 Answers1

0

Excel caches previously-registered functions for each add-in. The reason for caching is so that the functions are available for the user to see and trigger (causing your add-in to load automatically) even before the add-in gets loaded.

When you run the following code, all previous registered functions in the cache are removed and immediately replaced with the new ones you specify:

Excel.run(function (context) {        
    context.workbook.customFunctions.addAll();
    return context.sync().then(function(){});
}).catch(function(error){});

Edit: if you still see functions that you don't think are supposed to be registered after you call the code above, there are 2 likely possibilities:

  1. The "incorrect" functions were actually registered by a different add-in (perhaps an earlier test you were doing).
  2. The Excel.run call is failing (you can check the error parameter to see whether this is your problem)

It may be useful to manually clear your computer's registration-cache: delete the folder AppData\Local\Microsoft\Office\16.0\Wef\CustomFunctions

-Michael, PM for add-ins

Michael Saunders
  • 2,662
  • 1
  • 12
  • 21
  • The code snippet you've proposed is already part of the sample. Looks like this does not work reliable. Or was this behavior fixed in a specific Excel version? I am using version 1711 (build 8711.2037), 32bit. – Kai Nov 22 '17 at 15:26
  • I've added some additional info to my answer – Michael Saunders Nov 22 '17 at 18:09
  • @MichaelSaunders Is this still valid? I can't find this api using ExcelApi 1.1 – José Salgado Jan 14 '20 at 09:37