Office.Tab interface

表示单个选项卡及其应具有的状态。 有关代码示例,请参阅 更改加载项命令的可用性 和 创建自定义上下文选项卡。

注解

要求集: RibbonApi 1.1

使用方

示例

// Create an Office.Tab object (a contextual tab), set its visibility
// and add it to the ribbon.
async function showDataTab() {
    // Create the Office.Tab object.
    const myContextualTab = { id: "CtxTab1", visible: true };
    const ribbonUpdater = { tabs: [ myContextualTab ] };
    await Office.ribbon.requestUpdate(ribbonUpdater);
}

属性

controls

指定选项卡中的一个或多个控件,如菜单项、按钮等。

groups

指定选项卡上的一个或多个控制组。

id

清单中指定的选项卡的标识符。

visible

指定选项卡在功能区上是否可见。 仅与上下文选项卡一起使用。

属性详细信息

controls

指定选项卡中的一个或多个控件,如菜单项、按钮等。

controls?: Control[];

属性值

注解

当对象是传递给 Office.Ribbon 方法的 requestUpdateOffice.RibbonUpdaterData 对象的一部分时Tab,此属性指定其启用状态将更改的控件的 ID。 但是,如果选项卡上有 groups 属性,则此属性将被忽略,并且 controls 必须使用指定组的属性来更改已启用状态。

groups

指定选项卡上的一个或多个控制组。

groups?: Group[];

属性值

注解

当对象是传递给 Office.Ribbon 方法的 requestUpdateOffice.RibbonUpdaterData 对象的一部分时Tab,各种 Office.Group 对象的属性指定controls哪些控件的启用状态已更改; 将忽略对象的controls属性Tab。

要求集: RibbonApi 1.1

示例

/**
 * Shows or hides a contextual tab.
 */
async function setContextualTabVisibility(visible: boolean) {
    await Office.ribbon.requestUpdate({
        tabs: [
            {
                id: "ContextualTab1",
                visible: visible,
                groups: [
                {
                    id: "TableToolsGroup",
                    controls: [
                        { id: "FormatTableButton", enabled: true },
                        { id: "SortTableButton", enabled: true },
                    ],
                },
                ],
            },
        ],
    });
}

id

清单中指定的选项卡的标识符。

id: string;

属性值

string

示例

// Office.Tab objects are properties of ribbon updater objects that are passed to the 
// Office.ribbon.requestUpdate method. The following shows how to set the visibility of 
// a custom contextual tab.

async function showDataTab() {
    await Office.ribbon.requestUpdate({
        tabs: [
            {
                id: "CtxTab1",
                visible: true
            }
        ]});
}

// The the following does the same thing in TypeScript.

const showDataTab = async () => {
    const myContextualTab: Office.Tab = { id: "CtxTab1", visible: true };
    const ribbonUpdater: Office.RibbonUpdaterData = { tabs: [ myContextualTab ] };
    await Office.ribbon.requestUpdate(ribbonUpdater);
}

visible

指定选项卡在功能区上是否可见。 仅与上下文选项卡一起使用。

visible?: boolean;

属性值

boolean

注解

要求集: RibbonApi 1.2

示例

// Office.Tab objects are properties of ribbon updater objects that are passed to the 
// Office.ribbon.requestUpdate method. The following shows how to set the visibility of 
// a custom contextual tab.

async function showDataTab() {
    await Office.ribbon.requestUpdate({
        tabs: [
            {
                id: "CtxTab1",
                visible: true
            }
        ]});
}

// The following does the same thing in TypeScript.

const showDataTab = async () => {
    const myContextualTab: Office.Tab = { id: "CtxTab1", visible: true };
    const ribbonUpdater: Office.RibbonUpdaterData = { tabs: [ myContextualTab ] };
    await Office.ribbon.requestUpdate(ribbonUpdater);
}