Office.context.document.settings.get的问题 [英] Issue with Office.context.document.settings.get

查看:87
本文介绍了Office.context.document.settings.get的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下方法从Word文档中读取设置:

I'm reading settings from a Word Document using:

function callbackFunction(){
    var varValue = Office.context.document.settings.get("VariableName");
}

此呼叫是在拨打电话后立即进行的:

This call is made right after a call to :

Office.context.document.settings.refreshAsync(callbackFunction);

这些设置存储在有效的JSON字符串WebExtensionProperty中: 我可以在Open XML生产率工具中看到设置对象,没有问题

The settings are stored in a valid JSON String WebExtensionProperty: I can see the setting object in the Open XML productivity tool, without problem

We.WebExtensionProperty prop = new We.WebExtensionProperty(){ Name = "VariableName", Value = "{\"A\":\"1\"}" };
webExtensionPropertyBag1.Append(prop);

  • 当我从Visual Studio将Office-js加载项运行到Word(使用IE)时,该函数从WebExtensionProperty中存储的JSON字符串中返回正确的对象,
  • 当我将加载项侧面加载到Word(使用IE)时,该函数也可以正确返回,但是

    • When I run my office-js add-ins from Visual Studio into Word (Using IE), the function returns the correct object from the JSON string stored in the WebExtensionProperty,
    • When I sideload my add-ins into Word (Using IE), the function also returns correctly, but

      当我将加载项在线加载到Word中时(也使用IE,甚至使用Chrome),该功能始终返回null!

      When I sideload my add-ins into Word online (Also using IE, even with Chrome), the function always returns null!

      当我从OneDrive下载文档时,我的财产仍在文件中.

      When I download the document from OneDrive, my property is still in the file.

      我尝试使用json字符串中的简单变量,但是我从未设法使Word Online在这里返回任何值,而桌面上的Word始终可以完美地工作.

      I tried with simple variable in the json string, but I never managed to get Word Online ever return any value here, whereas Word on the Desktop always worked flawlessly.

      我需要做些什么来授权"使用此功能? 有人在Word Online中使用此方法感到幸运吗?

      Is there anything I need to do to 'authorize' the use of this function? Anyone having luck with this method in Word Online?

      我写入文件使用的设置是:

      The settings I write into the file use is:

      new We.WebExtensionStoreReference(){ Id = "MyUniqueId", Version = "1.0.0.0", Store = "\\\\localhost\\OfficeManifest", StoreType = "Filesystem" };
      

      当我在Word Online上使用它时,是否可能是因为侧面加载使同一加载项不在我的UNC路径中,因此Word Online无法加载该值?

      When I use it on Word online, could it be that the sideloading makes this same Add-ins not being in my UNC path, and therefore Word online can't load the value?

      在所有情况下,我在侧面加载时使用的清单都是相同的.

      The manifest I use when sideloading is the same in all cases.

      谢谢

      推荐答案

      此问题是侧面加载加载项的症状.对此有一点了解可能会有所帮助.

      This issue is a symptom of side-loading add-ins. A little background on this might help.

      某些外接程序功能(例如设置")被锁定到特定的外接程序.这样可以确保您的设置不会被另一个恰好使用相同设置名称的加载项所覆盖.当您从Office检索设置时,它仅返回最初归属于您的加载项的那些设置.此属性是从清单中的加载项ID中锁定的.

      Certain add-in functionality, such as Settings, is keyed to a specific add-in. This allows you to ensure your settings don't get overwritten by another add-in that just happened to use the same setting name. When you retrieve your settings from Office, it is returning only those settings originally attributed to your add-in. This attribution is keyed off the add-in's ID from your manifest.

      从商店或租户的加载项目录加载加载项时,加载项会从清单文件中为该加载项分配id.由于此值不变,因此您可以在跨平台和外接程序版本中维护设置.

      When an add-in is loaded from the Store or your tenant's add-in catalog, the add-in assigns the id for that add-in from your manifest file. Since this value doesn't change, it allows you to maintain settings across platforms and versions of your add-in.

      侧面加载的工作方式有所不同.当您侧加载外接程序时,Office将为其分配一个随机生成的ID.这样做是为了确保您的开发版本和生产版本可以在同一台计算机上并排共存.如果Office使用清单中的ID,则它将有效地删除外接程序的生产版本.

      Side-loading works differently. When you side-load an add-in, Office will assign it a randomly generated ID. This is done to ensure your development and production versions can co-exist side-by-side on the same machine. If Office used the ID from the manifest, it would effectively remove the production version of your add-in.

      在大多数情况下,侧面加载的影响不会对您的加载项产生影响.除非您尝试跨机器/平台测试设置",否则自动生成的ID会破坏外接程序与其设置之间的连接.

      In most cases, the effects of side-loading will have no effect on your add-in. That is unless you're attempting to test Settings across machines/platforms where the automatically generated ID breaks the connection between your add-in and it's settings.

      此问题的解决方法是使用开发者租户

      The workaround for this is to use a developer tenant and centrally publish your add-in there. This will automatically handle deployment of your add-in across each platform and ensure they all use the same ID value.

      这篇关于Office.context.document.settings.get的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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