context.application 在使用 WordApi 1.3 时未定义

context.application is undefined when using WordApi 1.3

使用 WordApi 1.3 应该可以使用新的 createDocument method 从 Web 插件中创建新文档。

但是,当使用文档中的以下示例片段时,context.applicationundefined

Word.run(function (context) {        // lets hold a valid base64 docx on this variable...        
    var myStartingDocAsBase64 = "some valid base64 encoded docx";
    var myNewDoc = context.application.createDocument(myStartingDocAsBase64); // note that the parameter is optional, a blank doc will be created otherwise               // at this point you can use the entire API on the myNewDoc document.. you can do things like        
    myNewDoc.body.insertParagraph("This is a new paragraph added via API", "end");        //now lets open the document, after this method is called,  you will no longer be able to modify the doc.....        
    myNewDoc.open();
    return context.sync();    
})
.catch(function (e) {
   console.log(e.message);
})

即使 Office.context.requirements.isSetSupported("WordApiDesktop", "1.3") returns 正确。

这已在 Windows 10 上的 Office 1611 中进行了测试(如下图所示)。

1.3 中的功能是否尚未完全实现,或者我们是否应该采取其他措施让 createDocument 正常工作?

您好,感谢您的提问。所有这些仍处于预览阶段,因此可能会发生变化。这里有一些指南。

  1. 1.There 不是 WordApiDesktop 要求集之类的东西,它已被删除并且很快将不再存在于 Office.js 中。这 事实上这是一个错误,所以感谢您报告此问题。
  2. 如果您看到您共享的文档页面,应用程序对象及其 createDocument 方法当前(并且可能会更改)在当前处于预览状态的 1.3 要求中。 (使用 office.js https://appsforoffice.microsoft.com/lib/beta/hosted/office.js 的预览CDN)

所以请不要使用 WordApiDesktop 要求,并确保您使用的是 Office.js

的 BETA CDN

拥有最新的 Office 来测试预览总是好的,如果您不是最新的,请查看此页面以获取帮助:https://github.com/OfficeDev/office-js-docs/blob/215f5d35490c943cc06c29b98357ba8cb034ec81/docs/develop/install-latest-office-version.md