Office.js在现有加载项中导入自定义功能

时间:2018-08-21 22:15:06

标签: office-js excel-addins custom-functions-excel

我试图将Office.js的预览功能中的Excel中的自定义功能合并到我编写的现有Excel加载项中。 Excel加载项正在使用Angular。现在,这两个项目都位于各自的文件夹中,并且在独立运行时可以很好地工作。我试图通过将文件从定制功能项目复制到我现有的外接程序项目中来将两者结合起来。我遵循与GitHub解决方案中推荐的架构完全相同的架构:OfficeDev/Excel-Custom-Functions

我苦苦挣扎的唯一部分是清单文件。根据文档,定义自定义功能的节点 必须位于清单的节点 AllFormFactors documentation)内文件。对于通过任务窗格加载的常规加载项(这是我所拥有的),将节点 加载到节点 ({{ 3}})。

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

但是,尽管这样做,我仍然收到一条错误消息,说我的自定义函数无法加载,并且我不知道问题出在哪里。我无法在网上真正找到答案,因此我们将不胜感激。谢谢!

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

<?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>

2 个答案:

答案 0 :(得分:0)

根据我的研究,我发现了这篇文章,其中一些评论可能为您提供了新的思路。例如“加入Office Insider程序”。供您参考,Add excel custom functions to an existing excel add-in - Javascript Api

答案 1 :(得分:0)

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

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

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