Worksheet Events


onActivated

Occurs when the worksheet is activated.

Excel.run(function (context) { 
    var sheet = context.workbook.worksheets.getItem("Sample");
    sheet.onActivated.add(function (event) {
        return Excel.run((context) => {
            console.log("The activated worksheet ID is: " + event.worksheetId);
            return context.sync();
        });
    });
    return context.sync();
});

onCalculated


Excel.run(function (context) { 
    var sheet = context.workbook.worksheets.getItem("Sample");
    sheet.onCalculated.add(function (event) {
        return Excel.run((context) => {
            console.log("The worksheet has recalculated.");
            return context.sync();
        });
    });
    return context.sync();
});

onChanged

Occurs when data changed on a specific worksheet.
Cell values have changed


Excel.run(function (context) { 
   context.workbook.worksheets.getItem("Sheet1").onDataChanged.add(event_onWorksheetDataChanged);

   return context.sync().then(function () {
      console.log("Done");
   });
}).catch(function (error) {
   console.log("Error: " + error);
   if (error.instanceof OfficeExtension.Error) {
     console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

function event_onWorksheetDataChanged(event) {
   return Excel.run(event, function (context) {
      var worksheet = event.worksheet;
      var changedRange = event.changedRange;
      var source = event.source;
      var changeType = event.changeType;

      worksheet.load("name");
      changeRange.load("address, cellCount");

       return context.sync().then(function () {
            console.log("Data Changed in worksheet " + worsheet.name +
                                     "Changed area address is " + changedRange.address +
                                     "Cell count in the range is " + changedRange.cellCount);

            console.log("Data Change comes from " + source);

            if (changedRange.cellCount == 1) {
                 var newValue = event.newValue;
                 var oldValue = event.oldValue;
                 console.log("One cell changed, value before is " + oldValue + ", new value is " + newValue);
            }

            if (changeType == "RowInsert") {
                console.log("Row inserted on row " + changedRange.address);
            }

    });
});
}

onColumnSorted



onDeactivated

Occurs when the worksheet is deactivated.


onFiltered



onFormatChanged



onRowHiddenChanged



onRowSorted



onSelectionChanged

Occurs when the selection changed on a specific worksheet.
Changes the selection or extends the selection area



onSingleClicked



© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext