问题

I am trying to add DocumentSelectionChanged
event handle in Excel online document (tested in all browsers). Creating this event is failing from last 15 days.
Please help me here
P.S: Same event working fine in Excel 2013 desktop environment
Office.context.document.addHandlerAsync(Office.EventType.DocumentSelectionChanged, function(eventArgs) {
console.log(eventArgs);
}, function(asyncResult) {
console.log(asyncResult);
});
OSF.DDA.AsyncResult {value: undefined, status: "failed", error: OSF.DDA.Error}error: OSF.DDA.Errorcode: 5001message: "An internal error has occurred."name: "Internal Error"proto: OSF.DDA.Errorconstructor: (n,t,i)proto: Objectstatus: "failed"value: undefined__proto__: OSF.DDA.AsyncResultconstructor: (n,t)proto: Object
Here is link to test at http://aka.ms/R2yi5b
回答1:
Thanks for your patience. I am glad to tell you that this fix has been deployed and it is working on all web browsers now. Thanks again for submitting your feedback.
Cheers, Sky
回答2:
Update (Nov 6th 2015, afternoon):
On further investigation, it appears that there is a known bug in Excel Online that is causing this issue. The regression was noticed and already fixed a couple of weeks ago, however the fix has not made it to all endpoints yet (which explains why some folks were seeing it, while others, myself included, were not). We are looking at ways in which we can expedite the patch rollout.
We'll keep this thread updated as the fix makes its way through the system.
Original answer (Nov 6th 2015, morning):
I just tried it, and am not seeing the failure.
One thing I have noticed, though, is that the code on the shared link has a bug. The syntax of addHandlerAsync is that it accepts first the event type, then a handler, and then a callback function to report whether the event-handling succeeded or not. In the case of the shared project, it looked like it was instead assumed that the second argument is the success handler, and the second one was a failure handler(?). Instead, for that last argument, you should check asyncStatus.status
to check the success state.
(function() {
'use strict';
// The initialize function must be run each time a new page is loaded
Office.initialize = function(reason) {
$(document).ready(function() {
app.initialize();
addDocumentHandler();
});
};
function addDocumentHandler() {
Office.context.document.addHandlerAsync(
Office.EventType.DocumentSelectionChanged,
eventHandler,
function(asyncResult) {
if (asyncResult.status == "succeeded") {
app.showNotification("Success", "Error handler was added");
} else {
app.showNotification("Error setting event: ", JSON.stringify(asyncResult));
}
}
);
function eventHandler(eventArgs) {
Office.context.document.getSelectedDataAsync(Office.CoercionType.Text, function(asyncResult) {
if (asyncResult.status == "succeeded") {
app.showNotification("Value of selection: ", asyncResult.value);
} else {
app.showNotification("Error", "Cannot read selection value");
}
});
}
}
})();
I tried using the Office API Tutorial App as well, the "SelectionChanged" tutorial. And there too everything works correctly. Could you try that?
~ Michael Zlatkovsky, developer on Office Extensibility team, MSFT
来源:https://stackoverflow.com/questions/33542902/office-eventtype-documentselectionchangedin-excel-not-working-in-all-web-brows