简体   繁体   English

将处理程序附加到DocumentSelectionChanged事件会禁用Office for Mac上的撤消堆栈

[英]Attaching an handler to DocumentSelectionChanged event disables the Undo stack on Office for Mac

We have run in to, what seems like, a bug in Office.js on Office for Mac . 我们已经在Office for Mac中运行Office.js中的错误。

If you attach an event handler to DocumentSelectionChanged event that calls Excel.run the standard Excel "undo" functionality gets disabled. 如果将事件处理程序附加到调用Excel.runDocumentSelectionChanged事件, Excel.run禁用标准Excel“撤消”功能。 And this remains disabled until the add-in is unloaded (ie the event handler is unhooked). 并且在卸载加载项之前保持禁用状态(即事件处理程序未被挂钩)。

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. 您可以通过(例如)复制此问题,使用Excel-Add-in-JS-CollegeCreditsTracker示例应用程序并在app.initialize方法中插入以下代码块。

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));
        }
    );

Note that this works fine on Excel Desktop an Excel Online. 请注意,这适用于Excel桌面和Excel Online。 Is there a specific reason, such as API version supported on Office for Mac, that this would be failing? 是否有一个特定的原因,例如Office for Mac支持的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). 关于一个不相关问题的答案表明,在新的API版本中有另一种处理选择更改的方法(尽管它没有说明如何)。 In which case, is that a possible workaround for this? 在这种情况下,这可能是一种解决方法吗?

We cannot use BindingChanged events because we want to know when the user moves in and out of bindings, when user switches worksheets etc. 我们不能使用BindingChanged事件,因为我们想知道用户何时进出绑定,何时用户切换工作表等。

只是想让每个人都知道Office团队已经解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM