Office.Settings not retrievable in Excel Online when created and set in Excel Desktop

纵然是瞬间 提交于 2021-01-28 01:52:32

问题


According to the API docs, the Office.Settings objects are saved per add-in and per document. That is, they are available only to the add-in that created them, and only from the document in which they are saved.

I'm a bit confused regarding the Office.Settings interface. I've created a gist in the ScriptLab Add-in where I set 2 setting objects (queries and queryIDs) and then retrieve them (log them to console).

Gist: https://gist.github.com/VivianVenter/e5489628384f96f2d3bf9a50aace8728

If I run this gist on Excel Desktop, then I can create the settings and retrieve them successfully. If I save this workbook and open it in Excel Online and run the gist again then I cannot retrieve the settings, it returns null for both settings object.

According to my knowledge the ScriptLab Add-in is the same for the Desktop and Online version, am I missing something, or is it the intention of OfficeJS to not make the settings available/visible in the Online version if it was created and set in the Desktop version?

Settings desktop found: The settings objects was found in Excel Desktop

Settings online null: The settings objects was NOT found in Excel Online


回答1:


Office add-in's setting is stored based on the add-in's id. And once it is installed by side-loading, a new id is allocated to the add-in every time. This means you can't sync settings on multiple platforms while developing.

Once you submitted the add-in to the AppSource, a static id from AppSource is allocated to the add-in and it is used while installing the add-in from AppSource.

So, you should submit the add-in to AppSource to test/implement this feature.




回答2:


Thanks for asking the question. I could not repro your issue. Could you please try my snippet as below?

async function getSetting() {
  await Excel.run(async (context) => {

    const settings = context.workbook.settings;
    settings.add("setting1", true);

    const count = settings.getCount();
    await context.sync();
    console.log(`We have totally ${count.value} settings.`);

    const setting1 = settings.getItemOrNullObject("setting1");
    setting1.load("value");
    await context.sync();
    console.log(`The setting1's value:` + setting1.value);

    const setting2 = settings.getItemOrNullObject("setting2");
    setting2.load("value");
    await context.sync();
    console.log(`The setting's value:` + setting2.value);

  });
}

the expected result on Desktop and Online should be the same as below.



来源:https://stackoverflow.com/questions/65720404/office-settings-not-retrievable-in-excel-online-when-created-and-set-in-excel-de

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