【发布时间】:2018-09-13 06:28:06
【问题描述】:
我正在使用“Office 插件的 JavaScript API”在我的 HTML 程序中创建 excel 文件。
但是,当我加载页面时,这会返回一条错误消息。
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/Office.js" type="text/javascript"></script>
<script>
Excel.run(function (context) {
console.log('Your code goes here.');
}).catch(function (error) {
console.log('error: ' + error);
});
</script>
<head>
这会返回错误消息“未捕获的引用错误:Excel 未定义”。
【问题讨论】:
-
我不确定如何使用这个 API。但是,我在这些文档中看到您需要等待
Office被初始化。有这个Office.onReady函数,在这个函数的回调中我认为你可以执行相关的任务。这里:github.com/OfficeDev/office-js-docs-pr/blob/master/docs/develop/… -
我还可以在控制台
Warning: Office.js is loaded outside of Office client中看到警告,我认为您需要将其加载到办公室客户端中。你需要更多地挖掘你想要通过这个实现的目标。
标签: javascript excel ms-office office-js referenceerror