none
Excel JavaScript add-in - Get last edited cell RRS feed

  • Question

  • Hey. How do I get the details of cell that was last edited (its value was updated)?

    Thanks!


    • Edited by avi12641 Tuesday, August 8, 2017 3:18 PM
    Tuesday, August 8, 2017 2:45 PM

All replies

  • Hi avi12641,

    currently Office JS Api provides limited functionality.

    there is no any event, function or property that can return last edited cell.

    you can also try to refer the documentation to verify the same.

    Understanding the JavaScript API for Office

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 9, 2017 5:25 AM
    Moderator
  • Hello,

    We could use DocumentSelectionChanged and BindingDataChanged event to get last edited cell.

    We could add binding to selected cell in DocumentSelectionChanged event, then we could use BindingDataChanged event to catch the change of the cell value.

    Here is the example to get old value after editing the cell.

        var oldCellValue;
    
        function addEventHandlerToDocument() {
            Excel.run(function (ctx) {
                var PreviousCell = ctx.workbook.getSelectedRange();
                PreviousCell.load("address,values");
                ctx.workbook.bindings.add(PreviousCell, "Range", "myBinding");
                return ctx.sync().then(function () {
                    Office.select("bindings#myBinding").addHandlerAsync(Office.EventType.BindingDataChanged, onBindingDataChanged);
                    oldCellValue = PreviousCell.values;
                });
            }).catch(errorHandler);
            Office.context.document.addHandlerAsync(Office.EventType.DocumentSelectionChanged, MyHandler);
        }
    
        function MyHandler(eventArgs) {    
            Excel.run(function (ctx) {
                var sourceRange = ctx.workbook.getSelectedRange().load("address,values");
                ctx.workbook.bindings.add(sourceRange, "Range", "myBinding");
                return ctx.sync().then(function () {
                    Office.select("bindings#myBinding").addHandlerAsync(Office.EventType.BindingDataChanged, onBindingDataChanged);
                    oldCellValue = sourceRange.values;
                });
            })
            .catch(errorHandler);
        }
    
        function onBindingDataChanged(eventArgs) {
            showNotification("old value", oldCellValue);
        }
    

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 15, 2017 9:39 AM
    Moderator