Kapila Ponnamperuma
Kapila Ponnamperuma

Reputation: 1

Why am I losing saved settings of my add-in in an Excel workbook

We have this issue around saved settings when we share workbooks among users. When we share workbooks, we sometimes notice that the saved settings are lost when the workbook is open by a different user using the same version of the add-in. We understand that this could happen when sideloading the add-in using the shared folder. However, when we use the AppSource, we observe settings are lost when a user creates the workbook from an add-in installed from in-app (get add-in option in Excel) and shared it with someone who installed the add-in from the office store (web).

Could someone explain what the dependencies are when we use Excel API to save and read settings?

This is how we save settings:

 saveData(data) {
      try {
        Office.context.document.settings.set("presets", JSON.stringify(data));
        Office.context.document.settings.saveAsync();
      } catch (e) {
        console.error(e);
      }
  }

This is how we read settings:

  getSavedData() {
    return JSON.parse(Office.context.document.settings.get('presets'));
  }

Upvotes: 0

Views: 118

Answers (1)

Rundong-MSFT
Rundong-MSFT

Reputation: 109

Thanks for your question, the method refreshAsync is recommended to read settings, you can try this:

Office.context.document.settings.refreshAsync((result: Office.AsyncResult<Office.Settings>) => {
      savedData = result.value.get('presets');
});

Thanks, Office Platform team.

Upvotes: 0

Related Questions