Excel JS API - SettingCollection not persisting

你说的曾经没有我的故事 提交于 2020-01-05 04:14:28

问题


I'm trying to update my Excel add-in to use the workbook SettingCollection instead of the Office.context.document.settings object. The documentation seems to suggest they are functionally equivalent, but with document.settings I can call saveAsync() and see my data persisted (in the PropertyBag in a webextensions.xml).

With ctx.workbook.settings.add('key', 'value'), I can get the settings and get them in the current session, but they don't get added to the webextensions.xml and aren't available on the next open of the add-in.

Is there a version of saveAsync for workbook settings that I'm missing? I assumed context.sync would take care of it, but I haven't had any luck.

Edit: I figured out what was causing my initial issue, but the problem is still there. When I close the browser tab with Excel Online and re-open it with my add-in, the settings are not persisting. Nothing is getting added to webextensions.xml.

Here is an example Excel.run()

window.Excel.run(async ctx => {
    ctx.workbook.settings.add('hello', 'world');
    await ctx.sync();
    let setting = ctx.workbook.settings.getItemOrNullObject('hello');
    setting.load('value');
    await ctx.sync();
    console.log(setting.value);
});

The setting 'hello' sets and exists the next if I relaunch my add-in, but not if I close the file and open my add-in.


回答1:


there is a bug with the Excel rich API for settings, can you please try the Shared API flavor as a workaround in the meantime...

function createSetting() { Office.context.document.settings.set("Foo", "bar"); Office.context.document.settings.saveAsync(); }

function readSetting() { console.log(Office.context.document.settings.get("Foo")); }



来源:https://stackoverflow.com/questions/51031343/excel-js-api-settingcollection-not-persisting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!