I have some problems when i use my Angular Excel Addin (Office js) in multiple opened Excel instances.
Before I describe the problem in more detail, I would like to give a short explanation of what the AddIn does:
The user can define UDF functions in Excel to fetch data from a server and display it in Excel. However, the UDF functions are not executed directly, but only when an update is triggered. After that, requests are sent to the server, the data is fetched, formatted and displayed in Excel. If the user clicks on the "Update" button, all worksheets in the workbook are iterated over and the corresponding UDF functions are searched for. The requests are sent directly to the server. Under certain circumstances, it can take some time to answer a request and to display the data in Excel (e.g. when a user has defined 100 UDF functions in 100 worksheets with each containing one UDF).
I currently have the following problems:
1) If the user has opened an Excel instance with UDF functions defined in 100 worksheets and another instance with 70 worksheets containing UDF functions, I get an "An unexpected server error occurred" error when I switch between the opened Excel instances. The update does not run through, sometimes requests are not sent at all or cannot be processed. I think the following code snippet could cause this problem:
Excel.run(async context => { const sheet: Excel.Worksheet = context.workbook.worksheets.getActiveWorksheet(); ... }
context.workbook always returns the currently open workbook or the one that is currently open in the active Excel instance. But I have not found a way to access a workbook by name or id.
Is it possible that the AddIn can only work properly in one instance or am I doing something wrong?
2) If you have started an update of a workbook via the AddIn (e.g. 100 worksheets with UDF functions) and Excel loses focus (e.g. by switching to Word or Edge), then as already mentioned under 1) not all requests are sent or processed.
I hope that some of you have already had similar problems and maybe have a solution for them.