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

戏子无情 提交于 2019-12-24 06:32:49

问题


We have run in to, what seems like, a bug in Office.js on Office for Mac.

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).

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

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?

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?

We cannot use BindingChanged events because we want to know when the user moves in and out of bindings, when user switches worksheets etc.


回答1:


Just want to let everyone know that this issue has been resolved by the Office team.



来源:https://stackoverflow.com/questions/44060020/attaching-an-handler-to-documentselectionchanged-event-disables-the-undo-stack-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!