Mar 13 2023 02:45 PM - edited Mar 13 2023 05:38 PM
Hi All,
I was taking a look at the ExcelScript API but unless I missed something I have the feeling that Event Listeners are not currently implemented in Office Scripts (TypeScript/ExcelScript) for Office 365's Excel for Web...
Essentially, I want to add an Event Listener to a Worksheet [ex. onChange.add()] so I can lock the active cell after any data has been inputted...
Are Event Listeners even available?
I'm not looking for anyone to write any code just a Yes or No answer to whether or not Event Listeners are implemented, and if Yes, a little nudge to the applicable API documentation.
Much appreciated,
Terry
Mar 14 2023 09:19 PM
SolutionMar 15 2023 04:26 PM
Thanks for looking into it and your alternative recommendation! Add-ins where my next line of investigation so it's reassuring to get your suggestion. Much appreciated
Mar 15 2023 07:16 PM
Mar 15 2023 07:18 PM - edited Mar 15 2023 07:21 PM
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
sheet.onSelectionChanged.add(function (event) {
return Excel.run(async (context) => {
console.log("The selected range has changed to: " + event.address);
await context.sync();
});
});
await context.sync();
});
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/30-events/events-worksheet.yaml
await Excel.run(async (context) => {
let sheet = context.workbook.worksheets.getItem("Sample");
sheet.onChanged.add(onChange);
await context.sync();
console.log("Added a worksheet-level data-changed event handler.");
});
Mar 15 2023 07:50 PM