I'm trying to use the Excel Javascript API to create an addin that:
- Adds multiple buttons on the Home tab.
- Each of the buttons opens the taskpane to a different screen.
- Each of these taskpanes runs in the same runtime (e.g. I can share data between them with just setting data in
window.data = "data"
).
As far as I understand, it is not possible to do this with multiple ShowTaskpane
actions on the buttons, as this does not appear work with the shared runtime.
The approach I'm taking currently is:
- Set my function file as
<FunctionFile resid="Taskpane.Url"/>
(where <bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html"/>
)
- Define the following actions:
<Control xsi:type="Button" id="FirstButton">
...
<Action xsi:type="ExecuteFunction">
<FunctionName>first</FunctionName>
</Action>
</Control>
<Control xsi:type="Button" id="SecondButton">
...
<Action xsi:type="ExecuteFunction">
<FunctionName>second</FunctionName>
</Action>
</Control>
- Define
first
andsecond
as a functions in the global scope (and defined in thetaskpane.html
file). Each of these functions a) sets some state inside the Taskpane app (to get it to show something different, depending on the function call), then callsOffice.addin.showAsTaskpane()
. The code looks generally like:
However, this does not work as expected. Namely, it opens the taskpane in a separate iframe to the side of the taskpane. It looks like this:
When I add a Office.addin.showAsTaskpane()
call to the share
function, it looks like this:
How can I use the Execute functions actions but do so within the taskpane? I want one shared runtime, and I want all of it to open and be within the taskpane itself. The documentation makes it seem like AppDomains can make this happen, but I'm not sure what I'm doing wrong.
Thanks for any information -- I really appreciate it!
localStorage
or cookies? In other words, do you have to keep those changes in the memory, or is it OK to save them to localStorage for this purpose? You could still remove them from LS onunloaded
event – Selfsuggestion