Office.BeforeDocumentCloseNotification interface
表示当用户尝试关闭文档时可能出现的模式通知对话框。 在用户响应前,文档不会关闭。 通知对话框将允许用户确认关闭文档的请求或取消关闭文档的请求。 此 API 仅在 Excel 中受支持。
注解
要求集: SharedRuntime 1.2
使用方
示例
// Enable the before document close modal notification dialog.
async function enableNotification() {
await Office.addin.beforeDocumentCloseNotification.enable();
}
// Add an event handler to detect when the document close operation is cancelled.
Office.addin.beforeDocumentCloseNotification.onCloseActionCancelled(async function () {
// When the document close attempt is cancelled, write a message to the active range in the worksheet.
await Excel.run(async (context) => {
const range = context.workbook.getSelectedRange();
range.values = [["Detected onCloseActionCancelled event."]];
await context.sync();
});
});
方法
| disable() | 防止在用户试图关闭文档时出现通知对话框。
|
| enable() | 启用用户尝试关闭文档时显示的模式通知对话框。 在用户响应前,文档不会关闭。 此通知对话框要求用户确认关闭文档的请求,或者允许用户取消关闭文档的请求。
|
| on |
添加一个事件处理程序,用于检测关闭操作何时
|
方法详细信息
disable()
防止在用户试图关闭文档时出现通知对话框。
BeforeDocumentCloseNotification该 API 仅在 Excel 中受支持。
disable(): Promise<void>;
返回
Promise<void>
注解
要求集: SharedRuntime 1.2
示例
// Disable the dialog that pops up when the user tries to close the document.
async function disableCloseNotification() {
await Office.addin.beforeDocumentCloseNotification.disable();
}
enable()
启用用户尝试关闭文档时显示的模式通知对话框。 在用户响应前,文档不会关闭。 此通知对话框要求用户确认关闭文档的请求,或者允许用户取消关闭文档的请求。
BeforeDocumentCloseNotification该 API 仅在 Excel 中受支持。
enable(): Promise<void>;
返回
Promise<void>
注解
要求集: SharedRuntime 1.2
示例
// Enable the dialog that pops up and asks the user for confirmation when they try to close the document.
async function enableCloseNotification() {
await Office.addin.beforeDocumentCloseNotification.enable();
}
onCloseActionCancelled(handler)
添加一个事件处理程序,用于检测关闭操作何时 BeforeDocumentCloseNotification 取消。 如果满足以下两个条件,将触发此事件处理程序。
加载项调用
enable对象上BeforeDocumentCloseNotification的方法。当通知对话框打开时,最终用户单击对话框中的“ 不关闭 ”按钮、单击对话框右上角的“关闭”按钮或按 Esc 键。
BeforeDocumentCloseNotification该 API 仅在 Excel 中受支持。
onCloseActionCancelled(
handler: () => void
): Promise<() => Promise<void>>;
参数
- handler
-
() => void
取消对话框时调用的事件处理程序。
返回
Promise<() => Promise<void>>
添加事件处理程序时解析的承诺。
注解
要求集: SharedRuntime 1.2