使用 Visual Studio 的 Excel Web 插件自定义函数 [英] Excel Web Add-in Custom Function using Visual Studio

查看:45
本文介绍了使用 Visual Studio 的 Excel Web 插件自定义函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 VS 2019 创建了 Excel Web Addin 项目,并尝试将自定义函数合并到该项目中.不幸的是,MSDN 上的所有文档都参考了 Yeoman 生成器,所以我不确定 VS 创建的项目不支持自定义函数还是我遗漏了什么?我在 HOST 下添加了以下因素

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>

所有的 URL 都指向我创建的文件

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" />

我的 CustomFunction.js 文件内容如下:

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);

})();

和 HTML 文件看起来像

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>

我可以成功调试项目,当我运行它时,Excel 打开但没有加载项.谁能指出正确的方向?

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?

推荐答案

您没有包含元数据的 JSON 存档:

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> 

您必须手动配置元数据 JSON :

You have to configure your metadata JSON manually :

手动创建 JSON

您可以创建一个包含 HTML、JS 和 JSON 档案的新文件夹.然后,您将它们指向清单(页面、脚本和元数据).

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

这篇关于使用 Visual Studio 的 Excel Web 插件自定义函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆