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



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

我唯一挣扎的部分是清单文件。根据文档,定义自定义函数的节点/> 需要位于清单文件的 AllFormFactors/>(AllFormFactors文档(<节点内。对于通过任务窗格加载的常规加载项(这是我所拥有的(,节点>/> 加载到节点(桌面外形文档(中。

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

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

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

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

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

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

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

根据我的研究,我发现了这篇文章,一些评论可能会为您提供新的想法。例如"加入 Office 预览体验计划"。供您参考,请将 excel 自定义函数添加到现有 excel 加载项 - Javascript API

最新更新