使用WordApi 1.3時,應該可以使用新的createDocument method從web addIns中創建新文檔。使用WordApi時context.application未定義1.3
但是,使用文檔中找到的以下示例代碼段時,context.application
是undefined
。
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")
返回true。
這是在Windows 10上的Office 1611中測試的(如下圖所示)。
1.3中的功能尚未完全實現嗎,還是我們應該採取其他措施以使createDocument
正常工作?
剛剛發現了描述相同問題的這個github問題(https://github.com/OfficeDev/office -js-DOCS /問題/ 385) –