Excel JS API-SettingCollection不持久 [英] Excel JS API - SettingCollection not persisting

查看:52
本文介绍了Excel JS API-SettingCollection不持久的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新Excel加载项以使用工作簿SettingCollection而不是Office.context.document.settings对象.该文档似乎表明它们在功能上是等效的,但是使用document.settings,我可以调用saveAsync(),并查看我的数据是否保留(在webextensions.xml中的PropertyBag中).

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).

使用ctx.workbook.settings.add('key', 'value'),我可以获取设置并在当前会话中获取它们,但是它们不会被添加到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.

我缺少工作簿设置的saveAsync版本吗?我以为context.sync会解决这个问题,但是我没有任何运气.

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.

我知道是什么引起了我的第一个问题,但是问题仍然存在.当我使用Excel Online关闭浏览器选项卡并使用外接程序重新打开它时,设置不会保留.什么都没有添加到webextensions.xml.

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.

这是一个示例Excel.run()

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);
});

如果重新启动加载项,则设置"hello"并存在下一个,但是如果我关闭文件并打开加载项,则设置为"hello".

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.

推荐答案

Excel富API的设置有一个错误,同时您可以尝试使用共享API来解决此问题吗?

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 createSetting() { Office.context.document.settings.set("Foo", "bar"); Office.context.document.settings.saveAsync(); }

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

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

这篇关于Excel JS API-SettingCollection不持久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆