Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement an 'undo' functionality for an Office Add-In using the JavaScript API

How to implement an 'undo' functionality for an Office Add-In using the JavaScript API?

Right now all changes made by an Add-In are non-reversible by the user and it appears that Microsoft is not working on an easy way to enable the Add-In changes being 'undoable'. Even though developers have been requesting this feature:

  • https://officespdev.uservoice.com/forums/224641-general/suggestions/10754793-add-a-method-to-copy-a-sheet-with-all-data-and-for
  • https://officespdev.uservoice.com/forums/224641-general/suggestions/6273172-allow-edits-made-by-office-js-api-functions-setda
like image 979
Jonas Kemper Avatar asked Jul 20 '16 17:07

Jonas Kemper


2 Answers

Thanks for bringing this up.

The fact that the undo stack gets cleared when you execute the APIs is -- for Excel -- unfortunately unavoidable. You get the same behavior in VBA or VSTO, and it has to do with the way that Excel is fundamentally designed. Perhaps we could be a tad better at remembering undos for trivial operations, but even the UI itself or Excel Online will clear away the undo stack for things like deleting a sheet.

That being said, I do appreciate both suggestions, and have already passed them along to the team. Namely:

  • Avoid clearing the undo stack on read-only operations; only clear it on 'write'.
  • Think about some sort of copying/serialization method for worksheets, so that there's a state to revert to.

We'll see what we can do.

like image 161
Michael Zlatkovsky - Microsoft Avatar answered Oct 19 '22 23:10

Michael Zlatkovsky - Microsoft


Note that this is something specific to Excel (which i see from your uservoice request), but should not be generalized to the other Office Applications. For instance, in Word the end user driven undos after API calls is supported.

like image 3
Juan Balmori Avatar answered Oct 19 '22 23:10

Juan Balmori