Mavi Domates
Mavi Domates

Reputation: 4521

Storing a value in Word client rather than the document

Is there any way to store a key/value pair in the Word client using the JS APIs which will be applicable to other documents as well? Something like the roamingSettings property which is available for Outlook APIs?

Upvotes: 2

Views: 151

Answers (2)

Iqbal
Iqbal

Reputation: 219

Unfortunately Office does not provide any option to save user settings for all documents. Instead you can save settings for one document.

In your case you should use cookies. Second option is if you can have a json file to save data.

I am working on a word add-in developed with an express.js server. I save user specific data in a json file. My client javascript file sends ajax requests to server to retrieve data and to store new data.

Upvotes: 1

Slava Ivanov
Slava Ivanov

Reputation: 6957

The following are options offered by Office.js API to persist values:

  • Use members of the JavaScript API for Office that store data as either:

    • Name/value pairs in a property bag stored in a location that depends on add-in type.
    • Custom XML stored in the document.
  • Use techniques provided by the underlying browser control: browser cookies, or HTML5 web storage (localStorage or sessionStorage).

In your case the best bet would be cookie or localStorage.

Reference article: Persisting add-in state and settings

Reference for project example on github: OfficeDev/Excel-Add-in-JavaScript-PersistCustomSettings

Upvotes: 3

Related Questions