必须始终设置Office.initialize吗? [英] Must Office.initialize always be set?

查看:104
本文介绍了必须始终设置Office.initialize吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Office.js任务窗格加载项,在用户对任务窗格UI执行特定操作之前,它对Office API不会执行任何操作. UI是angular.js SPA.因此,自然地,我不需要在Office.initilize上做任何事情.但是,我一直遇到以下错误,直到我给Office.initialize一个空函数.

I have an Office.js Task Pane add-in that doesn't do anything with the Office API until the user performs a specific action on the task pane UI. The UI is an angular.js SPA. So, naturally, there's nothing I need to do on Office.initilize. But, I kept running in to the below error until I gave Office.initilize an empty function.

SCRIPT5022:第11行中第10360列的未处理异常 https://localhost:44300/Scripts/Office/1/office.js 0x800a139e- JavaScript运行时错误:Office.js尚未完全加载. 请稍后重试或确保将初始化代码添加到 Office.initialize函数. office.js(11,10360)

SCRIPT5022: Unhandled exception at line 11, column 10360 in https://localhost:44300/Scripts/Office/1/office.js 0x800a139e - JavaScript runtime error: Office.js has not been fully loaded yet. Please try again later or make sure to add your initialization code on the Office.initialize function. office.js (11,10360)

摆脱这种情况的代码是:

The code that got rid of this was:

  <script type="text/javascript">
      Office.initialize = function (reason) {
          // Nothing to do here..
      }
  </script>

这是预期的行为吗? 顺便说一句,该错误不是立即发生的,也不是对任何API调用或用户交互的响应.看来它是从Office.js文件中的setTimeout抛出的.

Is this expected behavior? BTW, the error wasn't immediate or in response to any API calls or user interaction. It seemed it was being thrown off of a setTimeout inside Office.js file.

推荐答案

在加载运行时环境并且加载项已准备好开始与应用程序和托管文档进行交互时,必须进行Office.initialize事件,并且必须对其进行初始化作为代码文件开头的函数,以便从函数调用Office.context属性或Office的任何其他属性.

Office.initialize event occurs when the run time environment is loaded and the add-in is ready to start interacting with the application and hosted document and it must be initialized as a function at the beginning of the code file so that the Office.context property or any another property of office will be available when called from the functions.

参考链接: https://msdn.microsoft.com/en-us/library/office /fp161139.aspx https://msdn.microsoft.com/en-us/library/office /fp142255.aspx

因此,在您的情况下,您可能对此事件不做任何事情,但是应用程序中的任何其他代码正在使用office.js中的任何属性.

So in your scenario, it may be possible that you are not doing anything with this event but any another code in your app is using any property from office.js.

希望这会对您有所帮助.

Hope this will help you.

这篇关于必须始终设置Office.initialize吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆