Forum Discussion
Jorik
Jan 17, 2025Copper Contributor
Excel Javascript API: Question about Bindings
Hello, I've got a question about using Bindings in the Excel/Office Javascript API, especially regarding listening to binding updates. There are ways to listen to updates to specific bindings using...
Kidd_Ip
Jan 18, 2025MVP
May consider a workaround as a combination of periodic checks and event listeners.
Periodically Check for New Bindings: Use a timer to periodically check for new bindings in the workbook.
Add Event Listeners: Once a new binding is detected, add the necessary event listeners to it.
Code look like
async function checkForNewBindings() {
await Excel.run(async (context) => {
const bindings = context.workbook.bindings;
bindings.load("items");
await context.sync();
bindings.items.forEach(binding => {
if (!binding.onDataChanged) {
binding.onDataChanged.add((...) => {
// Handle the data changed event
});
}
});
});
}
// Run the check periodically (e.g., every 5 seconds)
setInterval(checkForNewBindings, 5000);
This script will periodically check for new bindings and add the onDataChanged event listener to each new binding it finds.