Office.Control interface
表示单个控件或命令及其应具有的状态。
注解
有关显示如何使用 Control 对象及其属性的代码示例,请参阅 更改加载项命令的可用性 和 创建自定义上下文选项卡。
要求集: RibbonApi 1.1
使用方
示例
// This snippet enables a control (a button) in a custom ribbon tab.
// Note that "MyButton", "OfficeAddinTab1", and "CustomGroup111" are defined in the manifest.
const enableButton = async () => {
const button: Control = { id: "MyButton", enabled: true };
const parentGroup: Group = { id: "CustomGroup111", controls: [button] };
const parentTab: Tab = { id: "OfficeAddinTab1", groups: [parentGroup] };
const ribbonUpdater: RibbonUpdaterData = { tabs: [parentTab] };
Office.ribbon.requestUpdate(ribbonUpdater);
}
属性详细信息
enabled
指示应启用还是禁用控件。 默认值为 true。
enabled?: boolean;
属性值
boolean
id
清单中指定的控件的标识符。
id: string;
属性值
string
visible
指定控件在自定义选项卡上是显示还是隐藏。默认值为 true。
visible?: boolean;
属性值
boolean
注解
要求集: RibbonApi 1.3
重要提示: 可以配置按钮和菜单控件的可见性,但无法配置菜单中各个项的可见性。
示例
// Hide the Export Report button from the ribbon.
const button: Office.Control = {
id: "Contoso.ExportReportButton",
visible: false
};
// Specify the button's parent group and tab.
const group: Office.Group = {
id: "Contoso.ReportingGroup",
controls: [button]
};
const tab: Office.Tab = {
id: "Contoso.UserToolsTab",
groups: [group]
};
// Apply the change to the ribbon.
const ribbonUpdater: Office.RibbonUpdaterData = { tabs: [tab] };
await Office.ribbon.requestUpdate(ribbonUpdater);