如何使用 setStartupBehavior API 调用? [英] How do I use the setStartupBehavior API call?

查看:94
本文介绍了如何使用 setStartupBehavior API 调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当文档首次在 Excel 中打开时,我尝试注册事件处理程序,如 文档.但是,它告诉我需要配置我的代码以包含以下内容:Office.addin.setStartupBehavior(Office.StartupBehavior.load);我不太确定我应该在哪里使用它.我使用 Office 的 yeoman 生成器创建了我的项目.

I am trying to register event handlers when a document first opens up in Excel as it shows in the documentation. However, it tells me that I need to configure my code to include this: Office.addin.setStartupBehavior(Office.StartupBehavior.load); I'm not too sure where I am supposed to use this. I created my project using the yeoman generator for Office.

推荐答案

这取决于您是希望用户决定加载项是否在文件打开时运行,或者您是否希望确保它运行.如果您希望用户做出决定,请在按钮或其他 UI 的事件处理程序中包含这行代码.有一个示例插件可以执行此操作:Excel 共享运行时方案.

It depends on whether you want the users to decide whether the add-in runs when the file opens or whether you want to ensure that it does. If you want the user to decide, include this line of code in an event handler for a button or other UI. There's a sample add-in that does this at: Excel shared runtime scenarios.

如果要确保加载项在文件打开时运行,请在 Office.initialize 方法或 Office.onReady 方法中包含代码行.第一次打开文件时,加载项不会立即运行,用户必须手动调用它.但是,此后,只要打开该文件,加载项就会运行.

If you want to ensure that the add-in runs whenever the file opens, then include the line of code in the Office.initialize method or Office.onReady method. The first time the file opens, the add-in will not run immediately and the user will have to manually invoke it. But, after that, the add-in will run whenever that file is opened.

这篇关于如何使用 setStartupBehavior API 调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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