如何解决0x800a138f - JavaScript 运行时错误:无法设置未定义或空引用的属性“CustomFunctions”
我正在开发新的办公插件。我能够使用 Visual Studio 2019 和 Office/SharePoint 开发工作负载(JavaScrip API)创建 Excel 加载项。另一方面,我正在尝试执行此示例:https://github.com/lindalu-MSFT/Excel-Custom-Functions#prerequisites
重点是:执行解决方案,excel运行但是Home.js这一行出现错误:
Excel.Script.CustomFunctions = {};
错误:
这是我的 HTML 代码:
<!DOCTYPE html>
<html>
<head>
<Meta charset="UTF-8" />
<Meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<Meta http-equiv="Expires" content="0" />
<title>Excel Add-In with Commands Sample</title>
<script src="Scripts/jquery-3.5.0.js" type="text/javascript"></script>
<script src="https://appsforoffice.edog.officeapps.live.com/lib/beta/hosted/office.js" type="text/javascript"></script>
<script src="Home.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
这是我的 XML 代码:
<?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>a8ec7572-9a78-4d27-9232-e72765183d11</Id>
<Version>1.0.0.0</Version>
<ProviderName>Contoso</ProviderName>
<DefaultLocale>en-US</DefaultLocale>
<displayName DefaultValue="Custom functions sample" />
<Description DefaultValue="A variety of sample custom functions."/>
<Hosts>
<Host Name="Workbook" />
</Hosts>
<DefaultSettings>
<SourceLocation DefaultValue="~remoteAppUrl/Home.html" />
</DefaultSettings>
<Permissions>ReadWriteDocument</Permissions>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
<Hosts>
<Host xsi:type="Workbook">
<DesktopFormFactor>
<ExtensionPoint xsi:type="CustomFunctions">
<Script>
<SourceLocation resid="functionsjs" />
</Script>
<Page>
<SourceLocation resid="functionshtml"/>
</Page>
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
<Resources>
<bt:Urls>
<bt:Url id="functionsjs" DefaultValue="~remoteAppUrl/Home.js" />
<bt:Url id="functionshtml" DefaultValue="~remoteAppUrl/Home.html" />
</bt:Urls>
</Resources>
</VersionOverrides>
</OfficeApp>
最后是js代码:
Office.initialize = function (reason) {
// Define the Contoso prefix.
Excel.Script.CustomFunctions = {};
Excel.Script.CustomFunctions["CONTOSO"] = {};
// add42 is an example of a synchronous function.
function add42(a,b) {
return a + b + 42;
}
Excel.Script.CustomFunctions["CONTOSO"]["ADD42"] = {
call: add42,description: "Finds the sum of two numbers and 42.",helpUrl: "https://www.contoso.com/help.html",result: {
resultType: Excel.CustomFunctionValueType.number,resultDimensionality: Excel.CustomFunctionDimensionality.scalar,},parameters: [
{
name: "num 1",description: "The first number",valueType: Excel.CustomFunctionValueType.number,valueDimensionality: Excel.CustomFunctionDimensionality.scalar,{
name: "num 2",description: "The second number",}
],options: { batch: false,stream: false }
};
Excel.run(function (context) {
context.workbook.customFunctions.addAll();
return context.sync();
}).catch(function (error) { });
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
};
你们能帮我找到解决这个问题的方向吗?
我检查了这些主题:
解决方法
我认为这是自定义函数的旧分支,因此您可能会尝试访问该版本的预览版本,并且随着我们的界面发生变化而不再起作用。
请参阅此处自定义函数的官方指南:https://aka.ms/customfunctions
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。