【问题标题】:Office.js Import custom functions in existing add-inOffice.js 在现有加载项中导入自定义函数
【发布时间】:2018-08-21 22:15:06
【问题描述】:

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

我唯一苦苦挣扎的部分是清单文件。根据文档,定义自定义函数的节点 需要位于清单文件的节点 (AllFormFactors documentation) 内。对于通过任务窗格加载的常规加载项(这是我所拥有的),节点 加载在节点 内(@987654323 @)。

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

但是,尽管这样做了,我仍然收到一个错误,说我的自定义函数无法加载,我不知道问题出在哪里。我真的无法在网上找到答案,所以任何帮助将不胜感激。谢谢!

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

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

【问题讨论】:

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


    【解决方案1】:

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

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

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

    【讨论】:

    • 谢谢凯尔。我的加载项可以有多个证书吗?我正在考虑从自定义函数项目中导入证书,但我的加载项项目中已经有受信任的证书(来自常规任务窗格加载项的证书)。
    • 是的,我认为应该可以。只需要一个可以解锁您的本地主机的证书。以前,对于任务窗格,您可以使用 UI 来请求浏览器信任。鉴于自定义函数是隐藏的(很快就会在纯 Javascript 运行时的上下文中运行),没有可用的 UI,因此需要预先信任证书。
    • 同样,您也可以在 Office Online 上旁加载您的加载项:docs.microsoft.com/en-us/office/dev/add-ins/testing/…。在这方面,由于一切都在同一个浏览器中运行,您可以简单地预先信任 localhost 站点,然后侧载加载项,也可以让您按 F12 使用浏览器调试工具。
    • 所以我将自定义函数项目中的证书导入到我的加载项项目中,并将它们添加为受信任的证书。它没有用。然后,我按照您引用的网站的说明在 Office Online 上侧载加载项。当我加载加载项时,我没有显示错误,但是当我输入自定义函数的名称时,它无法识别,只显示#NAME?在单元格中。
    【解决方案2】:

    根据我的研究,我找到了这篇文章,其中一些 cmets 可能会为您提供新的想法。例如“加入 Office 预览体验计划”。供您参考,Add excel custom functions to an existing excel add-in - Javascript Api

    【讨论】:

    • 谢谢西蒙,但是我已经尝试了该帖子的建议,但并没有解决我的问题。我仍然无法加载我的自定义函数。我也是 Office 预览体验计划的一员。如果您不是该程序的一部分,您甚至无法单独测试自定义函数。
    • 嗨@DavidRubino,您设法实现了解决方案吗?我也遇到了同样的问题
    • 嗨@JoséSalgado 我最终在我的项目中使用了与自定义函数不同的方法,因为它们仍处于预览模式。
    猜你喜欢
    • 2022-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-24
    相关资源
    最近更新 更多