2

I have created Excel Web Addin project using VS 2019 and trying to incorporate Custom Functions into this project. Unfortunately all the documentation on MSDN refer to Yeoman generator so I am not sure either VS created project doesn't support custom functions OR I am missing something? I have added following factor under HOST

<AllFormFactors>
          <ExtensionPoint xsi:type="CustomFunctions">
            <Script>
              <SourceLocation resid="CustomFunction.Script" />
            </Script>
            <Page>
              <SourceLocation resid="CustomFunction.Page" />
            </Page>
            <Namespace resid="CustomFunction.Namespace" />
          </ExtensionPoint>
        </AllFormFactors>

And all the URL point to the files which I created

<bt:Url id="CustomFunction.Script" DefaultValue="~remoteAppUrl/CustomFunctions/CustomFunction.js" />
        <bt:Url id="CustomFunction.Page" DefaultValue="~remoteAppUrl/CustomFunctions/CustomFunction.html" />

My CustomFunction.js file content looks like:

// The initialize function must be run each time a new page is loaded.
(function () {
    Office.initialize = function (reason) {
        // If you need to initialize something you can do so here.
    };

    /**
     * Add two numbers
     * @customfunction
     * @param {number} first First number
     * @param {number} second Second number
     * @returns {number} The sum of the two numbers.
     */
    function add2(first, second) {
        return first + second;
    }

    CustomFunctions.associate("ADD2", add2);

})();
And HTML file look like

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Expires" content="0" />
    <title></title>
    <script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/custom-functions-runtime.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>

I can debug the project successfully and when I run it, Excel open but no add-in loaded into it. Can anyone point out the right direction please?

  • Will the add-in be loaded successfully when there's no Custom Function? Or the issue only happens when Customer Functions exist in the add-in? – Phoebe Yuan Jan 07 '21 at 02:41
  • Hi @Phoebe123, Yes Addin load successfully before making any change for Custom Function. Its really strange, all documentation of Custom Functions only use Yoeman generator (not VS). – user1455675 Feb 27 '21 at 07:48
  • Have you figured this out? I think that you can't create custom functions in VS 2019. In the manifest file I have this comment: So there is no place for AllFormFactors I guess. – Tomasz Decker Apr 01 '21 at 09:57

1 Answers1

0

You don't have the JSON archive with the metadata:

<AllFormFactors>
          <ExtensionPoint xsi:type="CustomFunctions">
            <Script>
              <SourceLocation resid="Functions.Script.Url" />
            </Script>
            <Page>
              <SourceLocation resid="Functions.Page.Url"/>
            </Page>
            <Metadata>
              <SourceLocation resid="Functions.Metadata.Url" />
            </Metadata>
            <Namespace resid="Functions.Namespace" />
          </ExtensionPoint>
        </AllFormFactors> 

You have to configure your metadata JSON manually :

Manually create JSON

You can create a new folder with HTML, JS, and JSON archives. Then, you point them in the manifest (page, script, and metadata).

DeSanterra
  • 81
  • 1
  • 1
  • 8