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");
}
});
}
属性
| async |
在传递到回调的 AsyncResult 对象的 asyncContext 属性中返回的任何类型的用户定义项,保持不变。 |
| selection |
指定是否选择参数指定 |
属性详细信息
asyncContext
在传递到回调的 AsyncResult 对象的 asyncContext 属性中返回的任何类型的用户定义项,保持不变。
asyncContext?: any
属性值
any
selectionMode
指定是否选择参数指定 id 的位置 (高亮显示) 。 使用 Office.SelectionMode 或等效字符串。 有关详细信息,请参阅备注。
selectionMode?: Office.SelectionMode | string
属性值
Office.SelectionMode | string