I am integrating with a third party app that uses content controls and custom XML parts to store values in Word. I created a function that binds each content control to its respective variable, and it works. Something like this:
await Office.context.document.bindings.addFromNamedItemAsync(contentControl.title, Office.BindingType.Text, { id: contentControl.title}, (asyncResult) =>
this.bindingFunction(asyncResult, context, contentControl, fieldName, fieldValue));
“bindingFunction” basically creates a few event handlers if a content control is modified for some math and other updates. The problem I’m running into is that this binding function takes almost a minute to run over the entire document upon opening – it’s a 10+ page document with hundreds of content controls. If I don’t call on the function on init, the bindings are gone the moment I close and reopen the document. Is there a quick way to save the bindings and just reapply them when the app/pane opens instead of having to get all content controls and run the binding function every time?
I tried getting the bindings and storing them:
Office.context.document.bindings.getAllAsync(async (result) => {
if (result.status === Office.AsyncResultStatus.Succeeded) {
this.bindings = result.value.map(binding => {
return {
id: binding.id,
data: binding.document.bindings
};
});
However, when I reopen it, this info doesn’t seem to be enough to reapply the bindings.