Search code examples
exceloffice365office-jsoffice-addinsexcel-addins

Excel add-in real-time changes


I am looking for a listener/event that would fire up when a user makes some change to a cell in Excel, so that my add-in can do some processing in the background i.e. save that change in the backend through a service call.

Currently, I save the data in a set of rows through service calls when the user clicks on the publish button in the add-in. However, it'd be nice if the user doesn't need to do this and instead a particular row gets saved as soon as the user changes something.

Is there any features like this in Office.js? Or perhaps some way to simulate it?


Solution

  • You can detect changes using Document.SelectionChanged event but this is likely pretty noisy. Clicking around the screen will trigger this so you'd want to make sure you would need some rather efficient code to detect actual changes or you'll just end up needlessly slowing down the user experience.

    A better option would be to bind to the data you want to track and use the Binding.bindingDataChanged event. This would only fire if and when the data you care about changes.

    The best option might be to reconsider the overall scenario. Using an add-in to save data to a backend is supported but it isn't a very slick experience for the user. A cleaner implementation might be to leverage Graph's Excel API to process changes when the document changes in OneDrive. This would make the entire process transparent to the user.