I have built an excel add-in in react typescript using the yeoman generator. My dialog is only opened through a button found within the custom tab I've created. As a developer, I want to allow a user run an excel function from a dialog that will update the worksheet.
I've read through the office documentation but can only find authentication related examples. Can anyone shed further light on this?
You can call some of the built-in Excel functions from an add-in. (See here.) But to do it from a dialog is tricky. The only Office.js APIs that are supported in the dialog are isSetSupported
and messageParent
. So, your button in the dialog can't directly call the workbook.functions
API. What you need to do is have the button in the dialog send a message back to the parent JavaScript runtime where displayDialogAsync
was called. The message identifies the function to be called. Code in the parent handles the MessageReceived event and calls the workbook.functions
API, passing the name of the function to be called. To the end user it looks like the button in the dialog is running the Excel function.