With WordApi 1.3 it should be possible to use the new createDocument method to create new documents from within the web addIns.
However, when using the example snippet below found in the documentation, context.application
is 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);
})
This is even though Office.context.requirements.isSetSupported("WordApiDesktop", "1.3")
returns true.
This is tested in Office 1611 on Windows 10 (shown in the image below).
Are the features in 1.3 not fully implemented yet, or should we do something else to get createDocument
to work?
Hello thanks for your question. All of this is still in preview and hence subject to change. Here is some guide for you.
So please don't use the WordApiDesktop requirement, and also make sure you are using the BETA CDN for Office.js
its allways good to have the latest Office to test the previews, check out this page for help in case you are not in latest: https://github.com/OfficeDev/office-js-docs/blob/215f5d35490c943cc06c29b98357ba8cb034ec81/docs/develop/install-latest-office-version.md