【发布时间】:2016-02-04 21:44:35
【问题描述】:
我正在为 Word 编写插件。我有 Word 2016。Office.context.requirements.isSetSupported('WordApi', 1.1) 在这种情况下应该返回 true,但它返回 false。 Word 对象未定义。有任何想法吗?谢谢。
Windows 7 Enterprise 上的 Microsoft Word 2016 MSO (16.0.6326.1022) 32 位
这是我的代码的一些 sn-ps:
在我的html 的head 中有这个:
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/Office.js" type="text/javascript"></script>
<script src="local/js/common.js"></script>
common.js 以
开头Office.initialize = function(reason) {
console.log(Office.context.requirememts)
if (Office.context.requirements.isSetSupported('WordApi', 1.1)) {
//never gets in here
}
else {
console.log("This add-in requires Word 2016 or greater.");
}
};
Office.context.requirememts 没有isSetSupported 功能
更新: 有一件事我认为不相关,但显然它是相关的。加载时我的 html 页面重定向到另一个 html 页面,这似乎是导致问题的原因。我有重定向的原因是因为当xml文件有
<SourceLocation DefaultValue="http://localhost/wordaddin/index.html"/>
而不是
<SourceLocation DefaultValue="C:\WordAddIn\index.html"/>
html文件的内容被缓存了,没有办法(至少我没有找到)清除这个缓存。因此,我在 index.html 中所做的任何更改都不会通过。因此,在加载 index.html 时,我会执行 window.location='main.html?'+datestamp,这可以解决问题,但后来我陷入了这种怪异状态。
这里是 index.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<script>
function init() {
var timestamp = new Date().valueOf();
window.location = "main.html?" + timestamp;
}
</script>
</head>
<body onload="init()">
</body>
</html>
【问题讨论】:
-
可以分享一下Word版本+版本号吗?你能确认这是 Word 2016 for Windows 吗?请发布您的代码。您尝试过的任何参考资料或来源都会有所帮助。
标签: office-js word-addins