将处理程序附加到DocumentSelectionChanged事件会在Office for Mac上禁用撤消堆栈 [英] Attaching an handler to DocumentSelectionChanged event disables the Undo stack on Office for Mac
问题描述
我们遇到了 Office for Mac 上的Office.js中的一个错误.
We have run in to, what seems like, a bug in Office.js on Office for Mac.
如果将事件处理程序附加到调用Excel.run
的DocumentSelectionChanged
事件,则会禁用标准Excel撤消"功能.直到卸载加载项(即取消解除事件处理程序)之前,此选项都保持禁用状态.
If you attach an event handler to DocumentSelectionChanged
event that calls Excel.run
the standard Excel "undo" functionality gets disabled. And this remains disabled until the add-in is unloaded (i.e. the event handler is unhooked).
例如,您可以通过使用Excel-Add-in-JS-CollegeCreditsTracker
示例应用程序并在app.initialize
方法中插入以下代码块来复制此问题.
You can replicate this problem by (for example), taking the Excel-Add-in-JS-CollegeCreditsTracker
sample app and inserting the following block of code in app.initialize
method.
Office.context.document.addHandlerAsync(
Office.EventType.DocumentSelectionChanged,
function () {
Excel.run(function (ctx) {
var activeCell = ctx.workbook.getSelectedRange();
activeCell.load(["address", "worksheet", "rowIndex", "columnIndex", "values", "formulas"]);
return ctx.sync().then(function () {
app.showNotification(activeCell.address);
});
}).catch(function (err) {
console.log(err);
});
},
null,
function (asyncResult) {
console.log("Handler added: " + JSON.stringify(asyncResult));
}
);
请注意,这可以在Excel Desktop和Excel Online上正常运行. 是否有特定原因(例如Office for Mac支持的API版本)会失败?
Note that this works fine on Excel Desktop an Excel Online. Is there a specific reason, such as API version supported on Office for Mac, that this would be failing?
关于一个不相关问题的答案提示,在较新的API版本中,存在另一种处理选择更改的方法(尽管它不说如何).在这种情况下,这可能是一种解决方法吗?
This answer on an unrelated question suggests that there's an alternative way to handle selection change in newer API versions (although it doesn't say how). In which case, is that a possible workaround for this?
我们不能使用BindingChanged事件,因为我们想知道用户何时移入和移出绑定,何时切换工作表等.
We cannot use BindingChanged events because we want to know when the user moves in and out of bindings, when user switches worksheets etc.
推荐答案
只想让所有人都知道Office团队已经解决了这个问题.
Just want to let everyone know that this issue has been resolved by the Office team.
这篇关于将处理程序附加到DocumentSelectionChanged事件会在Office for Mac上禁用撤消堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!