我们遵循了以下关于启用iable ribbon命令的参考资料,但仍然不清楚。
1) 当加载项运行时,我们可以禁用2) 但不能根据其他命令事件启用一个ribbon命令。
请提供一些例子.
尝试了下面的方法,但不知道在哪里调用方法。启用按钮.
const enableButton = async () => {
const button: Control = {id: "MyButton", enabled: true};
const parentTab: Tab = {id: "OfficeAddinTab1", controls: [button]};
const ribbonUpdater: RibbonUpdaterData = { tabs: [parentTab]};
await Office.ribbon.requestUpdate(ribbonUpdater);
}
@Rick... 对不起,缺少参考资料。也是你提到的那个作为参考,下面是我们的尝试和异常得到。恳请建议。
WORD AROUND TRIED:
Office.onReady(async () => {
enableButton();
});
const enableButton = async () => {
var button = {id: "Menu", enabled: true};
var parentTab = {id: "Tab1", controls: [button]};
var ribbonUpdater = { tabs: [parentTab]};
await Office.ribbon.requestUpdate(ribbonUpdater);
}
ISSUE :
1) Uncaught (in promise) RichApi.Error: 你正在尝试使用的API不可用。它可能在不同的场景下可用.在new c(https:/appsforoffice.microsoft.comlib1.1hostedexcel-web-16.00.js:24:293355。)at c.f.processRequestExecutorResponseMessage (https:/appsforoffice.microsoft.comlib1.1hostedexcel-web-16.00.js:24:354008。)在 https:/appsforoffice.microsoft.comlib1.1hostedexcel-web-16.00.js:24:352113。
2) taskpane.js:14734 Uncaught (in promise) RichApi.Error: 你试图使用的API不可用。它可能会在不同的场景中可用.在new c (https:/appsforoffice.microsoft.comlibbetahostedexcel-web-16.00.js:24:293355。)at c.f.processRequestExecutorResponseMessage (https:/appsforoffice.microsoft.comlibbetahostedexcel-web-16.00.js:24:354008。)在 https:/appsforoffice.microsoft.comlibbetahostedexcel-web-16.00.js:24:352113。
你必须使用共享运行时,如启用和禁用加载项命令中所述](https:/docs.microsoft.comen-usofficedevadd-insdesigndisable-add-in-commands。). 这里有一个例子。共享运行场景,并带有一个使用启用功能的清单。