Office.GoToByIdOptions interface

Предоставляет варианты того, следует ли выбрать расположение, к которому выполняется переход.

Комментарии

Поведение, вызываемое параметром options.selectionMode , зависит от приложения Office.

В Excel: Office.SelectionMode.Selected выделение всего содержимого в переплетном или именованном элементе. Office.SelectionMode.None для текстовых привязок выделяет ячейку; Для привязок матриц, привязок таблиц и именованных элементов выбирает первую ячейку данных (не первую ячейку в строке заголовка для таблиц).

В PowerPoint: Office.SelectionMode.Selected Выбор заголовка слайда или первого текстового поля на слайде. Office.SelectionMode.None ничего не выбирает.

В Word: Office.SelectionMode.Selected Выделение всего содержимого в привязке. Office.SelectionMode.None для текстовых привязок перемещает курсор в начало текста; При привязке матриц и таблиц выделяется первая ячейка данных (не первая ячейка в строке заголовка для таблиц).

Используется

Примеры

// Go to a binding by ID (Word and Excel).
// The following example shows how to:
// 1. Create a table binding using the addFromSelectionAsync method as a sample binding to work with.
// 2. Specify that binding as the binding to go to.
// 3. Pass an anonymous callback function that returns the status of the operation
//    to the callback parameter of the goToByIdAsync method.
// 4. Display the value on the add-in's page.
function gotoBinding() {
    // Create a new table binding for the selected table.
    Office.context.document.bindings.addFromSelectionAsync(Office.BindingType.Table, { id: "MyTableBinding" }, function (asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
            console.error("Action failed with error: " + asyncResult.error.message);
        } else {
            console.log("Added new binding with type: " + asyncResult.value.type + " and ID: " + asyncResult.value.id);
        }
    });

    // Go to binding by ID, setting option to ensure entire binding is selected.
    let goToByIdOptions: Office.GoToByIdOptions = {
        selectionMode: Office.SelectionMode.Selected
    };
    Office.context.document.goToByIdAsync("MyTableBinding", Office.GoToType.Binding, goToByIdOptions, function (asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
            console.error("Action failed with error: " + asyncResult.error.message);
        } else {
            console.log("Navigation successful");
        }
    });
}

// Go to a table in a spreadsheet (Excel).
// The following example shows how to:
// 1. Specify a table by name as the table to go to.
// 2. Pass an anonymous callback function that returns the status of the operation
//    to the callback parameter of the goToByIdAsync method.
// 3. Display the value on the add-in's page.
function goToTable() {
    Office.context.document.goToByIdAsync("Table1", Office.GoToType.NamedItem, function (asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
            console.error("Action failed with error: " + asyncResult.error.message);
        } else {
            console.log("Navigation successful");
        }
    });
}

// Go to the currently selected slide by ID (PowerPoint).
// The following example shows how to:
// 1. Get the ID of the currently selected slides using the getSelectedDataAsync method.
// 2. Specify the returned ID as the slide to go to.
// 3. Pass an anonymous callback function that returns the status of the operation
//    to the callback parameter of the goToByIdAsync method.
// 4. Display the value of the stringified JSON object returned by asyncResult.value,
//    which contains information about the selected slides, on the add-in's page.
let firstSlideId = 0;
function gotoSelectedSlide() {
    // Get currently selected slide's ID.
    Office.context.document.getSelectedDataAsync(Office.CoercionType.SlideRange, function (asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
            console.error("Action failed with error: " + asyncResult.error.message);
        } else {
            firstSlideId = asyncResult.value.slides[0].id;
            console.log(JSON.stringify(asyncResult.value));
        }
    });
    
    // Go to slide by ID.
    Office.context.document.goToByIdAsync(firstSlideId, Office.GoToType.Slide, function (asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
            console.error("Action failed with error: " + asyncResult.error.message);
        } else {
            console.log("Navigation successful");
        }
    });
}

// Go to slide by index (PowerPoint).
// The following example shows how to:
// 1. Specify the index of the first, last, previous, or next slide to go to.
// 2. Pass an anonymous callback function that returns the status of the operation
//    to the callback parameter of the goToByIdAsync method.
// 3. Display the value on the add-in's page.
function goToSlideByIndex() {
    const goToFirst = Office.Index.First;
    const goToLast = Office.Index.Last;
    const goToPrevious = Office.Index.Previous;
    const goToNext = Office.Index.Next;

    Office.context.document.goToByIdAsync(goToNext, Office.GoToType.Index, function (asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
            console.error("Action failed with error: " + asyncResult.error.message);
        } else {
            console.log("Navigation successful");
        }
    });
}

Свойства

asyncContext

Определяемый пользователем элемент любого типа, возвращаемый без изменений в свойстве asyncContext объекта AsyncResult, передаваемого обратному вызову.

selectionMode

Указывает, выбрано ли (выделено) расположение, указанное параметром id . Используйте Office.SelectionMode или его эквивалент. Дополнительные сведения см. в комментариях.

Сведения о свойстве

asyncContext

Определяемый пользователем элемент любого типа, возвращаемый без изменений в свойстве asyncContext объекта AsyncResult, передаваемого обратному вызову.

asyncContext?: any

Значение свойства

any

selectionMode

Указывает, выбрано ли (выделено) расположение, указанное параметром id . Используйте Office.SelectionMode или его эквивалент. Дополнительные сведения см. в комментариях.

selectionMode?: Office.SelectionMode | string

Значение свойства