Office.js 在现有加载项中导入自定义函数

Office.js Import custom functions in existing add-in

我正在尝试将 Excel 中的自定义函数从 Office.js 的预览功能合并到我编写的现有 Excel 插件中。 Excel 加载项正在使用 Angular。现在,这两个项目在它们的文件夹中是分开的,并且在 运行 独立时工作得很好。我试图通过将自定义函数项目中的文件复制到我现有的加载项项目中来将两者结合起来。我遵循了 GitHub 解决方案中推荐的完全相同的架构:OfficeDev/Excel-Custom-Functions

我唯一遇到困难的部分是清单文件。根据文档,定义自定义函数的节点 < ExtensionPoint /> 需要位于节点 < AllFormFactors /> (AllFormFactors documentation) of the manifest file. For a regular add-in loaded through the taskpane (which is what I have), the node < ExtensionPoint /> is loaded within the node < DesktopFormFactor /> (DesktopFormFactor documentation).

在我的清单文件中,我复制了包含我的函数定义的节点 < AllFormFactors /> 并将其放在节点 < DesktopFormFactor / 之前>。我使用清单文件验证器确保清单文件有效。我还将最新版本的清单文件复制到我的共享文件夹位置,我还清除了缓存以确保加载了最新版本。

但是,尽管如此,我还是报错说我的自定义函数无法加载,我也不知道问题出在哪里。我真的无法在网上找到答案,所以任何帮助将不胜感激。谢谢!

作为参考,这里是清单文件中包含的代码。

<?xml version="1.0" encoding="UTF-8"?>
<OfficeApp
          xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
          xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides"
          xsi:type="TaskPaneApp">
  <Id>08807c12-4cd2-4e47-927e-bce93ebeb036</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>David Rubino</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="Angular Add-in" />
  <Description DefaultValue="Testing an add-in with Angular" />
  <IconUrl DefaultValue="https://localhost:3000/assets/images/data-builder-80.png" />
  <HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/images/data-builder-80.png"/>
  <SupportUrl DefaultValue="http://contoso.com/support" />
  <AppDomains>
    <AppDomain>https://login.microsoftonline.com</AppDomain>
  </AppDomains>
  <Hosts>
    <Host Name="Workbook" />
  </Hosts>
  <DefaultSettings>
    <SourceLocation DefaultValue="https://localhost:3000/index.html" />
  </DefaultSettings>
  <Permissions>ReadWriteDocument</Permissions>
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
    <Hosts>
      <Host xsi:type="Workbook">
        <AllFormFactors>
                    <ExtensionPoint xsi:type="CustomFunctions">
                        <Script>
                            <SourceLocation resid="JS-URL" />
                        </Script>
                        <Page>
                            <SourceLocation resid="HTML-URL"/>
                        </Page>
                        <Metadata>
                            <SourceLocation resid="JSON-URL" />
                        </Metadata>
                        <Namespace resid="namespace" />
                    </ExtensionPoint>
                </AllFormFactors>
        <DesktopFormFactor>
          <GetStarted>
            <Title resid="Contoso.GetStarted.Title"/>
            <Description resid="Contoso.GetStarted.Description"/>
            <LearnMoreUrl resid="Contoso.GetStarted.LearnMoreUrl"/>
          </GetStarted>
          <FunctionFile resid="Contoso.DesktopFunctionFile.Url" />
          <ExtensionPoint xsi:type="PrimaryCommandSurface">
            <CustomTab id="TabNavigator">
              <Group id="Contoso.Group1">
                <Label resid="Contoso.Group1Label" />
                <Icon>
                  <bt:Image size="16" resid="Navigator.data_builder_16x16" />
                  <bt:Image size="32" resid="Navigator.data_builder_32x32" />
                  <bt:Image size="80" resid="Navigator.data_builder_80x80" />
                </Icon>
                <Control xsi:type="Button" id="Navigator.Login">
                  <Label resid="Navigator.Login.Label" />
                  <Supertip>
                    <Title resid="Navigator.Login.Label" />
                    <Description resid="Navigator.Login.Tooltip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="Navigator.login_16x16" />
                    <bt:Image size="32" resid="Navigator.login_32x32" />
                    <bt:Image size="80" resid="Navigator.login_80x80" />
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                    <TaskpaneId>ButtonId1</TaskpaneId>
                    <SourceLocation resid="Contoso.Taskpane.Url" />
                  </Action>
                </Control>
                <Control xsi:type="Button" id="Navigator.Refresh">
                  <Label resid="Navigator.Refresh.Label" />
                  <Supertip>
                    <Title resid="Navigator.Refresh.Label" />
                    <Description resid="Navigator.Refresh.Tooltip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="Navigator.refresh_16x16" />
                    <bt:Image size="32" resid="Navigator.refresh_32x32" />
                    <bt:Image size="80" resid="Navigator.refresh_80x80" />
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                    <TaskpaneId>ButtonId1</TaskpaneId>
                    <SourceLocation resid="Contoso.Taskpane.Url" />
                  </Action>
                </Control>
                <Control xsi:type="Button" id="Contoso.TaskpaneButton">
                  <Label resid="Contoso.TaskpaneButton.Label" />
                  <Supertip>
                    <Title resid="Contoso.TaskpaneButton.Label" />
                    <Description resid="Contoso.TaskpaneButton.Tooltip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="Navigator.data_builder_16x16" />
                    <bt:Image size="32" resid="Navigator.data_builder_32x32" />
                    <bt:Image size="80" resid="Navigator.data_builder_80x80" />
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                    <TaskpaneId>ButtonId1</TaskpaneId>
                    <SourceLocation resid="Contoso.Taskpane.Url" />
                  </Action>
                </Control>
              </Group>
              <Label resid="Contoso.Group1Label" />
            </CustomTab>
          </ExtensionPoint>
        </DesktopFormFactor>
      </Host>
    </Hosts>
    <Resources>
      <bt:Images>
        <bt:Image id="Navigator.data_builder_16x16" DefaultValue="https://localhost:3000/assets/images/data-builder-16.png" />
        <bt:Image id="Navigator.data_builder_32x32" DefaultValue="https://localhost:3000/assets/images/data-builder-32.png" />
        <bt:Image id="Navigator.data_builder_80x80" DefaultValue="https://localhost:3000/assets/images/data-builder-80.png" />
        <bt:Image id="Navigator.login_16x16" DefaultValue="https://localhost:3000/assets/images/login-16.png" />
        <bt:Image id="Navigator.login_32x32" DefaultValue="https://localhost:3000/assets/images/login-32.png" />
        <bt:Image id="Navigator.login_80x80" DefaultValue="https://localhost:3000/assets/images/login-80.png" />
        <bt:Image id="Navigator.refresh_16x16" DefaultValue="https://localhost:3000/assets/images/refresh-16.png" />
        <bt:Image id="Navigator.refresh_32x32" DefaultValue="https://localhost:3000/assets/images/refresh-32.png" />
        <bt:Image id="Navigator.refresh_80x80" DefaultValue="https://localhost:3000/assets/images/refresh-80.png" />
      </bt:Images>
      <bt:Urls>
        <bt:Url id="Contoso.Taskpane.Url" DefaultValue="https://localhost:3000/index.html" />
        <bt:Url id="Contoso.GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812" />
        <bt:Url id="Contoso.DesktopFunctionFile.Url" DefaultValue="https://localhost:3000/function-file/function-file.html" />
        <bt:Url id="JSON-URL" DefaultValue="https://localhost:3000/config/customfunctions.json" />
        <bt:Url id="JS-URL" DefaultValue="https://localhost:3000/src/customfunctions.js" />
        <bt:Url id="HTML-URL" DefaultValue="https://localhost:3000/src/customfunctions.html" />
      </bt:Urls>
      <bt:ShortStrings>
        <bt:String id="Contoso.TaskpaneButton.Label" DefaultValue="Data Builder" />
        <bt:String id="Contoso.Group1Label" DefaultValue="D&amp;P Navigator" />
        <bt:String id="Contoso.GetStarted.Title" DefaultValue="Get started with your sample add-in!" />
        <bt:String id="Navigator.Login.Label" DefaultValue="Login" />
        <bt:String id="Navigator.Refresh.Label" DefaultValue="Refresh" />
        <bt:String id="namespace" DefaultValue="CONTOSO" />
      </bt:ShortStrings>
      <bt:LongStrings>
        <bt:String id="Contoso.TaskpaneButton.Tooltip" DefaultValue="Click to Show a Taskpane" />
        <bt:String id="Contoso.GetStarted.Description" DefaultValue="Your sample add-in loaded succesfully. Go to the HOME tab and click the 'Show Taskpane' button to get started." />
        <bt:String id="Navigator.Login.Tooltip" DefaultValue="Login to your Duff &amp; Phelps account to get started." />
        <bt:String id="Navigator.Refresh.Tooltip" DefaultValue="Update all the connected Data Builder cells within the existing workbook." />
      </bt:LongStrings>
    </Resources>
  </VersionOverrides>
</OfficeApp>

根据我的研究,我发现了这篇文章,其中一些评论可能会为您提供新的思路。比如"join the Office Insider program"。供您参考,

看起来您正在使用 https,我认为,考虑到您的清单通过了验证(这很好),问题可能是 Excel 无法访问您的 functions.json。

要解决此问题,您需要确保在加载自定义函数之前您的证书是可信的。有关更多信息,请参见此处:https://github.com/OfficeDev/generator-office/blob/master/src/docs/ssl.md(我们会在我们的文档中使其更加明显)。

我们还在努力添加日志记录功能作为清单运行时日志记录的一部分,以便我们可以更好地指示失败的原因。